+ 6
How to get the execution time of a code fragment in nanoseconds using chrono?
I have a function and I wish to get the time taken by the compiler to execute it (the runtime). But as the process can be fast, I wish to get the time in nanoseconds, to see all changes. I tried using chrono, like this: using namespace chrono; auto start = high_resolution_clock::now(); /* code block */ auto end = high_resolution_clock::now(); cout<<duration_cast<nanoseconds>(end - start) . count(); However, I just get a 0. Please help me correct my code!
4 Respuestas
+ 11
have you looked here:http://en.cppreference.com/w/cpp/chrono/duration
+ 7
@Ace
Sir, why is it that with a steady clock like in your program, I could get a non-zero value but with a high resolution clock, I couldn't?