title: How to get the CPU cycle count in x86_64 from C++?
body: <p>I saw this post on SO which contains C code to get the latest CPU Cycle count:</p>
  
  <p><a href="https://stackoverflow.com/questions/3830883/cpu-cycle-count-based-profiling-in-c-c-linux-x86-64">CPU Cycle count based profiling in C/C++ Linux x86_64</a></p>
  
  <p>Is there a way I can use this code in C++ (windows and linux solutions welcome)? Although written in C (and C being a subset of C++) I am not too certain if this code would work in a C++ project and if not, how to translate it?</p>
  
  <p>I am using x86-64</p>
  
  <p>EDIT2:</p>
  
  <p>Found this function but cannot get VS2010 to recognise the assembler. Do I need to include anything? (I believe I have to swap <code>uint64_t</code> to <code>long long</code> for windows....?)</p>
  
  <pre><code>static inline uint64_t get_cycles()
  {
    uint64_t t;
    __asm volatile ("rdtsc" : "=A"(t));
    return t;
  }
  </code></pre>
  
  <p>EDIT3:</p>
  
  <p>From above code I get the error: </p>
  
  <blockquote>
    <p>"error C2400: inline assembler syntax error in 'opcode'; found 'data
    type'"</p>
  </blockquote>
  
  <p>Could someone please help?</p>