Code:
#include<sys/time.h>#include<time.h>#include<stdio.h>typedef unsigned long long ticks;static __inline__ ticks getticks(void){ unsigned a, d; asm("cpuid"); asm volatile("rdtsc" : "=a" (a), "=d" (d)); return (((ticks)a) | (((ticks)d) << 32));}int main(){ int r = 0; ticks tick,tick1,tickh; unsigned long long time =0; tick = getticks(); sleep(10); tick1 = getticks(); time = (unsigned)((tick1-tick)/1662543); printf("/ntime in MS %llu/n",time);return 0;}
cat /proc/cpuinfo gives Code:
pprocessor : 0vendor_id : GenuineIntelcpu family : 6model : 14model name : Genuine Intel(R) CPU T2300 @ 1.66GHzstepping : 8cpu MHz : 1662.543cache size : 2048 KBfdiv_bug : nohlt_bug : nof00f_bug : nocoma_bug : nofpu : yesfpu_exception : yescpuid level : 10wp : yesflags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss tm pbe constant_tsc up arch_perfmon bts pni monitor vmx est tm2 xtprbogomips : 3328.87clflush size : 64