getting elapsed time in milliseconds

T

Thomas Baier

Hi there,

I need to know how to get the elapsed time in milliseconds. I tried
time_t start,end;
time(start);
do_something();
time(end);

double dif = difftime(end, start);

but this only returns the elapsed time in seconds.
So how can I get it in milliseconds?


Thanks for hlep

Thomas
 
W

WW

Thomas said:
I need to know how to get the elapsed time in milliseconds. I tried [SNIP]
So how can I get it in milliseconds?

By a high resolution timer facility provided by your operating system, if it
provides one. Not possible to do only using standard C++ language features.
Please post your question to a newsgroup dedicated to yiur
compiler/platform.
 
T

Thomas Baier

Thomas Baier wrote:

I'm working under Suse Linux 8.2 with g++. Maybe anybody in this newgroup
could answer my question now. Or could anybody tell me a good newsgroup to
post?


Thomas
 
A

Alf P. Steinbach

Thomas Baier wrote:

I'm working under Suse Linux 8.2 with g++. Maybe anybody in this newgroup
could answer my question now. Or could anybody tell me a good newsgroup to
post?

This group is not "please find a newsgroup for me".

Please don't post any more such questions (read the FAQ etc. about
topicality, in other words, RTFM).

That said, try [comp.os.linux.development.*].
 
J

J. Campbell

Thomas Baier said:
Hi there,

I need to know how to get the elapsed time in milliseconds. I tried
time_t start,end;
time(start);
do_something();
time(end);

double dif = difftime(end, start);

but this only returns the elapsed time in seconds.
So how can I get it in milliseconds?


Thanks for hlep

Thomas

The following will do what you want:


int main(){
int clo = clock();
//do stuff
cout << (clock() - clo) << endl;
return 0;
}
 
K

Kevin Goodsell

J. Campbell said:
The following will do what you want:


int main(){
int clo = clock();
//do stuff
cout << (clock() - clo) << endl;
return 0;
}

clock() is not a function for retrieving elapsed (real) time, and it's
result is not measured in milliseconds. clock() gives *processor time*,
and the precision it uses depends on the implementation.

-Kevin
 
J

J. Campbell

Kevin Goodsell said:
clock() is not a function for retrieving elapsed (real) time, and it's
result is not measured in milliseconds. clock() gives *processor time*,
and the precision it uses depends on the implementation.

-Kevin

Thanks for the heads-up. On my implimentation, clock() returns
milliseconds with circa 15 ms precision, and I'd assumed (always
imprudent) that it worked the same across the board. I dug a little
and learned of the CLOCKS_PER_SEC constant, which will help a bit for
gross measurements. Thanks for keeping me on the
straight-and-narrow...
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top