Measure ContextSwitch Time C (Windows) -


I need to implement a method that can measure time switch and CPU cycle between threads in Windows.

This is my code

  #include & lt; Stdio.h & gt; #include & lt; Windows.h & gt; # Include & lt; Time.h> LARGE_INTEGER initial timestamp, final timestamp, freak; DWORD Thread Procurement (LPVOID LPDVetredParam) {SwitchToHead (); Return 0; } Int main () {int results; Handle hThread; QueryPerformanceFrequency (& amp; freq); HThread = CreateThread (NULL, 0, (LpiTrade_RUTI) thread process, zero, 0, 0); QueryPerformanceCounter (& amp; initialTimeStamp); SwitchToThread (); QueryPerformanceCounter (& finalTimeStamp); Results = (1000000 * (QuadPart - the initial timestamp .Quadpart) / 2) / freq.QuadPart; Printf ("Windows Thread - Time is of reference u \ ns \ n", results); Waiting for the cinematic object (hThread, INFINITE); Return 0;}  

Note: There is a division by two, because I have two context switches between the initial timestamp and the last timestamp.

Know that this is the best or the right way to do this. I do not get the time, but I'm not sure how to get multiple CPU cycles.

You actually have a thread that switchtothered () is actually burning the CPU chakras to create a reference switch if you have multiple cores in your CPU but still you get lots of results The amount of overhead on the basis of process is very meaningless. Rum which is the owner of the thread, which receives the status of quantum and TLB cache. It takes a lot of time to reload the TLB registers and remember the cache, the general number of throwing between approximately 2,000 and 10,000 cycles.


Comments