title: How to count clock cycles with RDTSC in GCC x86?
body: <p>With Visual Studio I can read the clock cycle count from the processor as shown below.
  How do I do the same thing with GCC?</p>
  
  <pre><code>#ifdef _MSC_VER             // Compiler: Microsoft Visual Studio
  
      #ifdef _M_IX86                      // Processor: x86
  
          inline uint64_t clockCycleCount()
          {
              uint64_t c;
              __asm {
                  cpuid       // serialize processor
                  rdtsc       // read time stamp counter
                  mov dword ptr [c + 0], eax
                  mov dword ptr [c + 4], edx
              }
              return c;
          }
  
      #elif defined(_M_X64)               // Processor: x64
  
          extern "C" unsigned __int64 __rdtsc();
          #pragma intrinsic(__rdtsc)
          inline uint64_t clockCycleCount()
          {
              return __rdtsc();
          }
  
      #endif
  
  #endif
  </code></pre>