Re: comparing algorithm perf.



I would like to compare the perf of two algorithms written in C.

time

Ensure they're running a long time, so give them lots of input or run
them 1000 times in a row.

I feel that time-based method are not enough reliable (for instance time
(1) gives different results for the same program).


Read the documentation for time (1). It gives three values:
1st real
2nd user
3rd sys

The first one is Wall-Clock time.
The second one is the time, the CPU spent in your program.
The third one is the time, the CPU spent executing system requests (e.g.
reading a file) on your program's behalf.

If the User time is in the minutes-range and the first one takes
considerably longer than the other one, you have your result. If they
take approximately the same time, you need to use more iterations ;-) If
they still only differ marginally, you also have your result.

It's the same with using gprof: gprof is based on an approximately 100Hz
frequency. If you try to measure 10ms, you'll get bad results. If you
measure 100sec you get very good results...

Ciao...
.