- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Pranith,
It's true in that the concept of core cycles aren't able to be used in a reliable manner anymore, since the Turbo Boost or power states alter the frequency. The TSC Invariant was developed to address this issue through ticking at a set rate, regardless of CPU frequency However, the frequency of ticking isn't available through an API.
The two most commonly used methods to deal with this are:
CPUID 0x15/0x16 For newer Intel processors, they will give users the crystal clock as well as the multiplier, allowing you to determine TSC frequency. TSC frequency.
Calibration with QueryPerformanceCounter - On Windows, you can record both __rdtsc() and QueryPerformanceCounter values over a known time interval (for example 100 ms) and derive the TSC frequency once at startup.
If you're just looking for wall clock timing, using QPC is the most straightforward option since in modern Windows it's already supported by the standard TSC.
If you're switching between minutes, seconds and hours when doing benchmarking, it's a good idea to have it's a good idea to have a quick reference, such as an hour calculator
It can help you check your calculations when you convert TSC ticks into human-readable time.
This method provides stable and repeatable measurements across both power and core states.
Best Regards

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page