Re: comparing algorithm perf.



Bernhard Agthe a écrit :
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...

I see two problems with "time (1)" solution:

1. You can only monitor a "full program", and I don't want initialisations stuff to be taken into acount in my comparison. I want to compare two equivalent loops that are part of two distinct programs.
Both algos may take different time to initialise, I don't care about it.

2. if you launch time twice with the same program and same data, you get two different results, which lets me think it depends on the load of your machin.

Anyway, thank for you answer.

I will have a look at gprof...


















.



Relevant Pages

  • Re: comparing algorithm perf.
    ... 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 ... It's the same with using gprof: gprof is based on an approximately 100Hz ...
    (comp.os.linux.development.apps)
  • Re: comparing algorithm perf.
    ... 3rd sys ... The third one is the time, the CPU spent executing system requests (e.g. ... initialisations stuff to be taken into acount in my comparison. ... your machin. ...
    (comp.os.linux.development.apps)