By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,498 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,498 IT Pros & Developers. It's quick & easy.

getting elapsed time in milliseconds

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
WW
Thomas Baier wrote:
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.

--
WW aka Attila
Jul 19 '05 #2

P: n/a
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
Jul 19 '05 #3

P: n/a
On Sat, 20 Sep 2003 19:26:50 +0200, Thomas Baier <th****@tho-bai.de> wrote:
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.*].

Jul 19 '05 #4

P: n/a
Thomas Baier <th****@tho-bai.de> wrote in message news:<3f***********************@newsread2.arcor-online.net>...
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;
}
Jul 19 '05 #5

P: n/a
J. Campbell wrote:
Thomas Baier <th****@tho-bai.de> wrote in message news:<3f***********************@newsread2.arcor-online.net>...
So how can I get it in milliseconds?


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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #6

P: n/a
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<cd***************@newsread3.news.pas.earthli nk.net>...
J. Campbell wrote:
Thomas Baier <th****@tho-bai.de> wrote in message news:<3f***********************@newsread2.arcor-online.net>...
So how can I get it in milliseconds?


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


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...
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.