i need a program to get the CPU ticks at certain points of my program. So, i thought about using the clock function, but i'm having a hard time figuring out how it really works. I wrote this simple program to try to understand it but it made me feel more confused:
A few clues like what computer, what os, and what compiler would help But in general...
for(i=1; i<1000000; i++);
is really equivalent to
i=1000000;
and your compiler may be smart enough to remove the loop especially if the optimizer is turned on. Look at the options for your compiler to be sure that you aren't optimizing. If you are not optimizing, specify the option to use a symbolic debugger. Some compilers that would otherwise remove a loop will leave it in under that circumstance. If you know your systems assembler, use the the option to produce assembly code to see what is happening. You also may have a #pragma available to influence stuff like this...check you compiler's docs for that.
A very important point - the C standard does not say anyhting about the granularity of clock() - a compiler can have it check time once a second and increment the
variable by CLOCKS_PER_SEC.
This means it is possible depending on your implmentation, that you can get zero, CLOCKS_PER_SEC, CLOCKS_PER_SEC * 2 and so on, never getting any intermediate value. Don't use clock() if you need high granularity.
gettimeofday() returns a timeval struct. You can get a start value and an end value.
I think I posted on the forums how to do a delta of the times in timeval structs.
getrusage() returns CPU time, which is more useful than elapsed time on a multiprocessing box.
In the event you want cpu information, just using
at the commandline gives you the same information without having to instrument your code for getrusage().
Hello.
I would like to do this :
A_VAR_FLAG = "ABCD" +------------+...................................+---------+
...............................|.................|...................................|.............|... (7 Replies)
This is a strange one, I've never seen anything like it; the realtime clock doesn't tick while the computer's idle, only when you're watching it. Leave for 3 hours and it'll be 3 hours off. It still advances when it's off however, or the time would be far more incorrect than it is.
About all... (10 Replies)
Hey everyone! Can someone help me, i need to make a program using awk, that displays the current time (hh/mm/ss), i would really apreciate it! Thanks!
Alex. (4 Replies)
Hi there!!!
Need your help in solving some tricky problems.
Since clock() as such is buggy on SUN OS 5 we have started using gettimeofday() in our RTOS applications based on Solaris 9.
The problems we actually encountered previously were - the applications kind of freeze/hang eternally on... (1 Reply)
Hi
We had a AIX box built last year but was set to the correct GMT time, but using DST time zone. In march this year the clocks went forward without issues. (if I remember a couple of weeks early due to the DST zone)
This year we decided to change the clock to the correct time zone before... (0 Replies)
Hey ppl, i was wonddering, in mandrake, how to get the clok to display the time in non-military format....hehe thank you im just tired of looking at 18:00 hehe thank you (2 Replies)