user1978386
user1978386

Reputation: 257

How to get time in milliseconds or nanoseconds in C++

The thing is about getting time in C++ in form of milliseconds or nanoseconds. However I only know the way to get time in seconds like this:

#include <ctime>
...
time = ctime(0) ;
...

I want to know how to do similar operation to get time in milliseconds or nanoseconds. What headers I should include, what functions to call and what are their arguments ?

Upvotes: 0

Views: 3692

Answers (1)

dkackman
dkackman

Reputation: 15579

If you are ok with a platform specific implementation (windows) look at the QueryPerformanceCounter API.

And this answer has a quick example of usage.

Upvotes: 1

Related Questions