Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/dataStructures/hash/perf/cycTime.cpp
00001 #include "stdinc.h"
00002 #include "Util.h"
00003 
00004 using namespace grafalgo;
00005 
00006 int64_t i386_clock64(void)
00007 {
00008  uint32_t hi, lo;
00009  uint64_t v64;
00010 
00011  /* rdtsc: Loads the time-stamp counter value into %edx:%eax */
00012  asm volatile ("cpuid; rdtsc; movl %%edx, %0; movl %%eax, %1" /* Read the counter */
00013      : "=r" (hi), "=r" (lo)                  /* output */
00014      :                                       /* input (none) */
00015      : "%edx", "%eax");                      /* Let gcc know whch registers are used */
00016 
00017  v64 = ((uint64_t)hi << 32) + (uint64_t)lo;
00018 
00019  return (int64_t)v64;
00020 }
00021 
00022 int main() {
00023 
00024         for (int i = 1; i <= 20; i++) {
00025                 int64_t cyc0 = i386_clock64(); uint32_t t0 = Util::getTime();
00026                 usleep(20000);
00027                 int64_t cyc1 = i386_clock64(); uint32_t t1 = Util::getTime();
00028                 cout << (cyc1-cyc0) << " cycles, " << (t1-t0) << " us,"
00029                      << (cyc1-cyc0)/(t1-t0) << " cycles/us\n";
00030         }
00031 }
 All Classes Files Functions Variables Typedefs Friends