Questions tagged [high-resolution-clock]

24 questions
48
votes
7 answers

How to create a high resolution timer in Linux to measure program performance?

I'm trying to compare GPU to CPU performance. For the NVIDIA GPU I've been using the cudaEvent_t types to get a very precise timing. For the CPU I've been using the following code: // Timers clock_t start, stop; float elapsedTime = 0; // Capture…
sj755
  • 3,944
  • 14
  • 59
  • 79
25
votes
10 answers

How can I get the Windows system time with millisecond resolution?

How can I get the Windows system time with millisecond resolution? If the above is not possible, then how can I get the operating system start time? I would like to use this value together with timeGetTime() in order to compute a system time with…
21
votes
5 answers

High resolution timer in C#

Is there a high resolution timer that raises an event each time the timer elapses, just like the System.Timer class? I need a high resolution timer to Elapse every ms. I keep running into posts that explain that the Stopwatch can measure high…
bas
  • 13,550
  • 20
  • 69
  • 146
19
votes
9 answers

Microsecond resolution timestamps on Windows

How do I get microsecond resolution timestamps on Windows? I am loking for something better than QueryPerformanceCounter and QueryPerformanceFrequency (these can only give you an elapsed time since boot and are not necessarily accurate if they are…
Nikhil
  • 2,230
  • 6
  • 33
  • 51
14
votes
8 answers

Microsecond accurate (or better) process timing in Linux

I need a very accurate way to time parts of my program. I could use the regular high-resolution clock for this, but that will return wallclock time, which is not what I need: I needthe time spent running only my process. I distinctly remember seeing…
rix0rrr
  • 9,856
  • 5
  • 45
  • 48
13
votes
4 answers

High-resolution timer for iPhone?

I'm looking for high-resolution timing code for iPhone, in order to do some performance timings. I'd like to write code like this: HighResolutionTimer* myTimer = [[HighResolutionTimer alloc]init]; [myTimer start]; [self…
zpasternack
  • 17,838
  • 2
  • 63
  • 81
12
votes
3 answers

How to convert std::chrono::high_resolution_clock::now() to milliseconds, microseconds, ...?

I got this code from How to get duration, as int milli's and float seconds from ? #include #include int main (int argc, char *argv[]) { auto t0 = std::chrono::high_resolution_clock::now(); auto t1 =…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
11
votes
4 answers

Calculating function time in nanoseconds

I need to know how can I calculate the time of a function in C code in nanoseconds. I tried to repeat the function until consume some microseconds. Are there any other functions in time.h that can be used to calculate the time in nanoseconds?
Mousa Farajallah
  • 167
  • 1
  • 1
  • 11
7
votes
6 answers

High Resolution Timing Part of Your Code

I want to measure the speed of a function within a loop. But why my way of doing it always print "0" instead of high-res timing with 9 digits decimal precision (i.e. in nano/micro seconds)? What's the correct way to do it? #include…
neversaint
  • 60,904
  • 137
  • 310
  • 477
3
votes
3 answers

std::chrono::high_resolution_clock based frame timer

I have been using the following clock definition for a frame timer for years now: using frame_clock = std::conditional_t< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, …
3
votes
2 answers

How to declare a variable for high resolution clock in C++?

In the example here: https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now They declared the clock time point with auto. auto start = std::chrono::high_resolution_clock::now(); and the doc says it returns 'A time point representing the…
D.Zou
  • 761
  • 8
  • 25
2
votes
1 answer

When is it more appropriate to use gethrvtime() instead of gethrtime()

Manpage for gethrtime() mentions another flavor of this call, which is gethrvtime(), and explains that this is the virtual time of a LWP. I am trying to understand the use case that would require gethrvtime() and make gethrtime() inapplicable and…
evolvah
  • 625
  • 4
  • 15
2
votes
2 answers

error: 'high_resolution_clock' has not been declared

I am using g++ version 8.1.0 on windows 10 but still when I try to compile auto start=high_resolution_clock::now(); rd(n); auto stop=high_resolution_clock::now(); auto duration =…
theebugger
  • 77
  • 9
2
votes
1 answer

How to write std::chrono::high_resolution clock class template specialization only if it is not alias

I want to write class template specializations for std::chrono::system_clock, std::chrono::steady_clock, and std::chrono::high_resolution_clock. I wrote a straight forward code as follows: #include template struct…
2
votes
2 answers

get process start time in kernel module solaris

I am trying to get process start time in kernel module. I get the proc struct pointer, and from the proc I take field p_mstart () typedef struct proc { ..... /* * Microstate accounting, resource usage, and real-time profiling */ hrtime_t p_mstart; …
ilansch
  • 4,784
  • 7
  • 47
  • 96
1
2