473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

getting elapsed time in milliseconds

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
6 85984
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JSmith | last post by:
I want to determine the elapsed time between two events. What is the best way to do this?
12
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
9
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.