0

I have below output from gprof for my program:

Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00    30002     0.00     0.00  insert
  0.00      0.00     0.00    10124     0.00     0.00  getNode
  0.00      0.00     0.00     3000     0.00     0.00  search
  0.00      0.00     0.00        1     0.00     0.00  initialize

I have done optimizations and the run time I have is 0.01 secs(this is being calculated on a server where I'm uploading my code) which is the least I am getting at the moment. I am not able to reduce it further, though I want to. Does the 0.01 sec run time of my program has anything to do with the sampling time I see above in gprof output. Call graph is as below:

gprof -q ./a.out gmon.out 
             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name
                0.00    0.00   30002/30002       main [10]
[1]      0.0    0.00    0.00   30002         insert [1]
                0.00    0.00   10124/10124       getNode [2]
-----------------------------------------------
                0.00    0.00   10124/10124       insert [1]
[2]      0.0    0.00    0.00   10124         getNode [2]
-----------------------------------------------
                0.00    0.00    3000/3000        main [10]
[3]      0.0    0.00    0.00    3000         search [3]
-----------------------------------------------
                0.00    0.00       1/1           main [10]
[4]      0.0    0.00    0.00       1         initialize [4]
-----------------------------------------------
 While using `time /bin/sh -c ' ./a.out < inp.in '` on my machine I get below which varies slightly on every run .
real    0m0.024s
user    0m0.016s
sys         0m0.004s

real    0m0.017s
user    0m0.008s
sys     0m0.004s

I am bit confused how to correlate time output and gprof o/p

yulian
  • 1,601
  • 3
  • 21
  • 49
Diwakar Sharma
  • 415
  • 1
  • 9
  • 26
  • Do you want help optimizing your code? It can't be done if we don't know your code and what it does. Or do you have a question about understanding `gprof` output? If so, it isn't clear what's the question. – ugoren Nov 12 '13 at 13:09
  • 1
    `gprof` measures time by counting samples. Samples happen every 10 msec. So you're on the edge between getting 0 and 1 samples. – Mike Dunlavey Nov 12 '13 at 13:23
  • 1
    To get a better measurement, run the code many times from inside `main()`. Aim for something like 5 seconds: enough to get good sampling without taking all day. – Peter Nov 12 '13 at 18:28

1 Answers1

0

According to your other question, you got it from 8 seconds down to 0.01 seconds. That's pretty good.

Now if you want to go further, first do as @Peter suggested in his comment. Run the code many times inside main() so it runs long enough to get samples.

Then you could try my favorite technique. It will be much more informative than gprof.

P.S. Don't worry about CPU percent. All it tells is if your machine is busy and not doing much I/O. It does not tell you anything about your program.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • I have managed to reduce runtime further with one big optimization. I was calling an insert into trie function with parameters as trie's root and a string. I was then using strlen to calculate length of string (this insert was getting called some 30k times). I was building this string in main. Now I just added one more parameter to insert func for string length, and passed the variable to it which was being used to build string. Lot of saving :) strlen overhead removed – Diwakar Sharma Nov 14 '13 at 13:08