function c++ to calculate microseconds

J

JoeC.nc

I search a function to calculate microseconds in a time istant

use clock() and CLOCKS_PER_SEC

for example, the following should give you the interval in ms from
when the first line was executed

int t = clock();
...
cout << "in ms " << ((static_cast<float>(t)/CLOCKS_PER_SEC)*1000);
 
J

JoeC.nc

use clock() and CLOCKS_PER_SEC

for example, the following should give you the interval in ms from
when the first line was executed

int t = clock();
...
cout << "in ms " << ((static_cast<float>(clock()-t)/
CLOCKS_PER_SEC)*1000);

sorry...correction
 
J

Juha Nieminen

use clock() and CLOCKS_PER_SEC

Note, however, that it's in no way guaranteed that the value returned
by clock() has microsecond resolution. The value may well increase eg.
in steps of 1/10 of a millisecond or whatever.

I'm not even sure it's possible in all systems to get clock values
with microsecond resolution (the hardware/OS may limit this).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,520
Latest member
KrisMacono

Latest Threads

Top