![]() |
|
#1
|
|||
|
|||
gettimeofday()Hi there! I'm trying to port a piece of code from windows to linux. In this code i use the function timeGettime() from a Microsoft library. I checked for the exsistence of a similar function that could return the time since an epoch in milliseconds. The only thing I foud is gettimeofday()... ---> www.penguin-soft.com
But it seems to have a lot of problems and a strange behaviour... Take a look at here: CPP / C++ / C Code:
If you run this, you'll notice that at the end what you get is not the time elasped since the program run, but a casual value, sometime also negative... What is wrong with that? Last edited by LuciWiz : 01-Nov-2006 at 15:52.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: gettimeofday()Quote:
In Linux, one of the best resources is "man" Enter "man gettimeofday" at a shell prompt, and you will discover that there are two counters: a seconds counter and a microseconds counter. The two counters together indicate the number of seconds and microseconds since the epoch. The total elapsed time between two function calls (in microseconds) would be given by 1000000 * (difference in seconds) + (difference in microseconds) Let's assume that at the start, we have this: seconds counter = 1162406644, usecs counter = 702525 and after a few seconds we enter 'q' and we see that seconds counter = 1162406647, usecs counter = 103550 The difference in the seconds counter is 3; the difference in the usecs counter is -598975 Then the elapsed time is 1000000 * 3 - 598975 = 2401025 microseconds Try it yourself: CPP / C++ / C Code:
A few runs: Code:
Regards, Dave |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Measuring time? Help! | smoothdogg00 | C++ Forum | 1 | 10-Apr-2006 09:19 |
| Click Ticks | dayrinni | C Programming Language | 1 | 20-Feb-2006 12:50 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The