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

4

1 回答 1

0

根据您的另一个问题,您将其从 8 秒缩短到 0.01 秒。这很不错。

现在,如果您想更进一步,请首先按照@Peter 在他的评论中建议的方式进行操作。在里面多次运行代码main(),让它运行足够长的时间来获取样本。

那你可以试试我最喜欢的技术。它将比 提供更多信息gprof

PS不要担心CPU百分比。它所告诉的只是你的机器是否很忙并且没有做太多的 I/O。它不会告诉您有关您的程序的任何信息。

于 2013-11-13T23:24:56.133 回答