468,496 Members | 1,795 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,496 developers. It's quick & easy.

function c++ to calculate microseconds

I search a function to calculate microseconds in a time istant
Jan 22 '08 #1
3 8630
On Jan 22, 5:17*am, Francesco <francesco.meli...@gmail.comwrote:
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);

Jan 22 '08 #2
On Jan 22, 6:06*am, JoeC...@gmail.com wrote:
On Jan 22, 5:17*am, Francesco <francesco.meli...@gmail.comwrote:
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>(clock()-t)/
CLOCKS_PER_SEC)*1000);

sorry...correction
Jan 22 '08 #3
Jo*****@gmail.com wrote:
On Jan 22, 5:17 am, Francesco <francesco.meli...@gmail.comwrote:
>I search a function to calculate microseconds in a time istant

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).
Jan 22 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Building Blocks | last post: by
1 post views Thread by beavenour | last post: by
33 posts views Thread by Pushkar Pradhan | last post: by
51 posts views Thread by Richard Hengeveld | last post: by
1 post views Thread by Ahmed Fat-hi | last post: by
2 posts views Thread by Michael Evans | last post: by
4 posts views Thread by lenygold via DBMonster.com | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.