- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to time my piece of code using performance counters.
I see that there we cannot use the cycle count from the cores due to turbo boost and various other frequency variations in the CPU.
For this I think I should use the Invariant TSC value provided by "getInvariantTSC()". But, there is no corresponding Invariant TSC frequency value which I need to calculate the time.
How do I get this frequency? Or should I use QueryPerformanceCounter/Frequency() on Windows?
Thanks,
Pranith
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get the TSC frequency from:
uint64 PCM::getNominalFrequency()
You can get the TSC with the Windows*intrinsic:
#include
unsigned __int64 __rdtsc(void);
You can check if the TSC is invariant with the above link (see http://software.intel.com/en-us/forums/showthread.php?t=101951)
Pat
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Pranith,
The answerdepends on what accuracy you need and what you mean by 'time my piece of code'.
In my experience, the TSC can provide nanosecond resolution with little overhead.
QueryPerformanceCounter can provide about microsecond resolution with more overhead.
You can look http://stackoverflow.com/questions/1739259/how-to-use-queryperformancecounter for an intro to QueryPerformanceCounter().
I can't find a reference to getInvariantTSC().
If you have an invariant TSC (see http://software.intel.com/en-us/forums/showthread.php?t=101951) then the TSC runs at the same rate regardless of Cstate, Pstate, turbo mode, etc.
Pat
The answerdepends on what accuracy you need and what you mean by 'time my piece of code'.
In my experience, the TSC can provide nanosecond resolution with little overhead.
QueryPerformanceCounter can provide about microsecond resolution with more overhead.
You can look http://stackoverflow.com/questions/1739259/how-to-use-queryperformancecounter for an intro to QueryPerformanceCounter().
I can't find a reference to getInvariantTSC().
If you have an invariant TSC (see http://software.intel.com/en-us/forums/showthread.php?t=101951) then the TSC runs at the same rate regardless of Cstate, Pstate, turbo mode, etc.
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By 'time my piece of code', I meant:
main()
{
warmup();
startCounters(start);
stopCounters(end);
timeToExecute = f(start, end);
}
I was referring to cpucounters.h in Intel PCM for getInvariantTSC(). That gives us the invariant clock ticks. But to get time from those ticks, I need the frequency at which this clock ticks.
I wanted to use performance counters to do this, but if I cannot get the invariant clock frequency, then I would use QueryPerformanceCounter/Frequency to time my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get the TSC frequency from:
uint64 PCM::getNominalFrequency()
You can get the TSC with the Windows*intrinsic:
#include
unsigned __int64 __rdtsc(void);
You can check if the TSC is invariant with the above link (see http://software.intel.com/en-us/forums/showthread.php?t=101951)
Pat
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page