I have a piece of code that I need to benchmark on a Olimex SAM9-l9260 board running a Linux version 2.6.26.3-olimex (dimitar@lindev.vm) (gcc version 4.2.3 (Sourcery 8) kernel.
Anybody have a clue if and how time.h works in this scenario (I don’t have to have processor time, wall-clock time is fine for me if that is the only one possible)…
Carl’s routine is dividing by CLOCKS_PER_SECOND, unless the post was subsequently edited.
I do have a few questions:
Exactly what is the nature of the unreasonable values? The routine is calculating the elapsed time in ticks per second (many times 1000 tps or 1 millisecond resolution). What values are you seeing? Any negative times?
What type of variables are t1 and t2? They should be 32 bit signed values (or 64 bit if clock(), which isn’t always an int on every platform. If clock() returns a 64 bit value, to avoid the 2037 rollover issue, then t1 and t2 need to be 64 bit variables.
Assuming the clock() is returning a signed value, it will eventually rollover (returning negative numbers). That means that t1 can be positive and t2 negative or vice-versa. You need to account for these cases, especially if the board is running for more than a few days.
What is the value of CLOCKS_PER_SECOND? It may not be right for your board. You may have to calculate your own value by calling time(), waiting it for it to change, capture clock() in t1, wait for time() to change again, capture clock() in t2, subtract t2 from t1 to see the number of clocks per second.
Worked some more on this and have some reporting to do…
After a good nights sleep and some measuring with a normal stopwatch the values does not seem unreasonable anymore… The times I am measuring are in the range of a few seconds and using printf and a stopwatch I get values within 1/10:th of a second… So it seems ok…