Your question depends entirely on the WHICH system you are using. Each system has its own functions for obtaining the current time. To find out how long the system has been running, you need to access one of the "high resolution performance counters". If you do not use a performance counter, you are usually limited by the accuracy of microseconds (or worse), which is practically useless when profiling the speed of a function.
On Windows, you can access the counter using the QueryPerformanceCounter () function. This returns an arbitrary number that is different on each processor. To find out how many ticks are in the counter == 1 second, call "QueryPerformanceFrequency ()".
If you are coding under a platform other than Windows, itβs just a Google performance counter and the system you are coding on, and it should tell you how you can access the counter.
Change (clarification)
This is C ++, just turn on windows.h and import "Kernel32.lib" (it seems they deleted my hyperlink, see the documentation at: http://msdn.microsoft.com/en-us/library/ms644904.aspx ). For C # you can use the "System.Diagnostics.PerformanceCounter" class.
source share