45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
|
/*
|
||
|
Organization: Technical University of Kosice (TUKE),
|
||
|
Department: Department of Electronics and Multimedia Telecommunications (DEMT/KEMT),
|
||
|
Faculties: Faculty of Electrical Engineering and Informatics (FEI),
|
||
|
Feld of study: Informatics,
|
||
|
Study program: Computer Networks,
|
||
|
School year: 3., Bachelor study, 2020/2021,
|
||
|
Author: Marek Rohac -- MR,
|
||
|
Compiler: Winlibs GCC -- MinGW-W64 x86_64-posix-seh, built by Brecht Sanders, v. 10.2.0,
|
||
|
-- also works with GCC 11.1.0
|
||
|
*/
|
||
|
|
||
|
#define __USE_MINGW_ANSI_STDIO
|
||
|
#include<stdio.h>
|
||
|
#include<windows.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
//cpucyclesS -- Start measure
|
||
|
static __inline__ uint64_t cpucyclesS(){
|
||
|
unsigned cycles_low, cycles_high;
|
||
|
__asm__ volatile ("CPUID\n\t"
|
||
|
"RDTSC\n\t"
|
||
|
"mov %%edx, %0\n\t"
|
||
|
"mov %%eax, %1\n\t": "=r" (cycles_high), "=r" (cycles_low)::
|
||
|
"%rax", "%rbx", "%rcx", "%rdx");
|
||
|
return (((uint64_t)cycles_high << 32) | cycles_low );
|
||
|
}
|
||
|
//cpucyclesE -- End measure
|
||
|
static __inline__ uint64_t cpucyclesE(){
|
||
|
unsigned cycles_low, cycles_high;
|
||
|
__asm__ volatile ("RDTSCP\n\t"
|
||
|
"mov %%edx, %0\n\t"
|
||
|
"mov %%eax, %1\n\t"
|
||
|
"CPUID\n\t": "=r" (cycles_high), "=r" (cycles_low)::
|
||
|
"%rax", "%rbx", "%rcx", "%rdx");
|
||
|
return (((uint64_t)cycles_high << 32) | cycles_low );
|
||
|
}
|
||
|
int main(){
|
||
|
uint64_t tick,tock;
|
||
|
tick=cpucyclesS();
|
||
|
Sleep(1000);
|
||
|
tock= cpucyclesE() - tick;
|
||
|
printf("Executed: %llu cycles\n", tock);
|
||
|
return 0;
|
||
|
}
|