繁体   English   中英

C:减少运行时间以进行优化

[英]C: reducing runtime for optimization

我的程序的gprof输出如下:

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

我已经进行了优化,运行时间为0.01秒(这是在我上传代码的服务器上计算的),这是我目前获得的最少时间。 我想进一步减少它。 我的程序的0.01秒运行时间是否与我在gprof输出中看到的采样时间有关? 调用图如下:

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

我有点困惑如何将time输出与gprof o / p相关

根据另一个问题,您将其从8秒降低到0.01秒。 很好

现在,如果您想走得更远,请按照@Peter在其评论中的建议进行操作。 main()多次运行代码,因此其运行时间足以获取样本。

然后,您可以尝试我最喜欢的技术 它会比gprof更多信息。

PS不用担心CPU百分比。 它只说明您的计算机是否繁忙并且没有执行太多I / O。 它不会告诉您有关程序的任何信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM