windows - CPU Cycle count as approximation for the number of executed instructions -


i trying measure cpu cycles spent executing code on windows. while running code above (visual c++ 11) i've noticed cpu cycles vary run run. there no explicit i/o involved, don't have clue why happening.

in general relation between cpu cycles spent thread , amount of instructions executed? can use cpu cycles approximation of that?

#include "stdafx.h" #include <windows.h> #include <iostream> #include <algorithm> int _tmain(int argc, _tchar* argv[]) {     unsigned __int64 thread_cycle1;     unsigned __int64 thread_cycle2;      handle thread_handle = getcurrentthread();     querythreadcycletime(thread_handle, &thread_cycle1);      // code profiling     int a[] = {1,3,4,5,6,7,23,4,2,6,7,8,9};     std::sort(a, + sizeof(a) / sizeof(a[0]));      querythreadcycletime(thread_handle, &thread_cycle2);      std::cout << thread_cycle2 - thread_cycle1 << " cycles";     return 0; } 

i think have generalize able cycles ~= # instructions executed. different instructions have different latencies.

you can find details @ following link @ least intel® 64 , ia-32:

http://www.intel.co.uk/content/dam/doc/manual/64-ia-32-architectures-optimization-manual.pdf

appendix c goes such latencies.

as why vary, other comment apply, since cache misses alter behaviour.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -