5

I tried profiling my C++ program with gprof. The program itself ran for about 53 seconds, so I dont understand why it says, main only ran for about 8.29 seconds. Any explanation on this?

Here is an excerpt:

index % time    self  children    called     name
                                                 <spontaneous>
[2]     20.5    0.00    8.29                 main [2]
                0.00    8.28       1/1           MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
                0.00    0.01       1/1           MPQS::MPQS(NTL::ZZ, long) [36]
                0.00    0.00       1/1           MPQS::~MPQS() [78]
-----------------------------------------------
                0.00    8.28       1/1           main [2]
[3]     20.5    0.00    8.28       1         MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
                7.15    1.08     801/801         MPQS::sieve() [4]
                0.00    0.04     801/801         MPQS::find_smooth_vals() [23]
                0.01    0.00       1/1           MPQS::try_solutions(NTL::mat_GF2&) [35]
                0.00    0.00     801/801         MPQS::compute_coeffecients() [59]
-----------------------------------------------
                7.15    1.08     801/801         MPQS::start(std::basic_ofstream<char, std::char_traits<char> >&) [3]
[4]     20.4    7.15    1.08     801         MPQS::sieve() [4]
                1.08    0.00     801/801         MPQS::find_candidates() [9]
Martin Lauridsen
  • 341
  • 4
  • 12
  • Is it measuring wall clock time or actually cumulative CPU time used by your process? – csl Jul 05 '10 at 14:54
  • Have you tried running your code through the unix `time` command? That'll show you wall clock time vs. user-space time (your code) vs. kernel time. Do you expect your code to be IO bound or CPU bound? – Rup Jul 05 '10 at 14:54
  • 1
    @Rup: The "MPQS" almost certainly stands for "Multiple polynomial quadratic sieve", an algorithm for factoring large numbers. I'd expect it to be *heavily* CPU bound. – Jerry Coffin Jul 05 '10 at 15:00
  • @Jerry Coffin: Indeed, MPQS is the multiple polynomial quadratic sieve :-) – Martin Lauridsen Jul 05 '10 at 18:42

1 Answers1

2

Were you printing results to the console? gprof doesn't count blocked time. See this.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • I timed by program using a GetTime() function, provided by the NTL C++ library. It measures the time the process is running on the CPU. It said about 53 seconds. I input to the program in the beginning, but my manual timing, using GetTime() does not start until after that. The 53 seconds fit very well with what I observed from looking at the clock on my computer. I have not tried running it with the time command, how do I do that? I do not know if I expect it to be CPU bound or IO bound. – Martin Lauridsen Jul 05 '10 at 15:00
  • 1
    Ahh, so of course gprof counts in the time I spend doing input to the program! This is why it says main is actually only run for such a small amount of time. I will try hardcoding my input into the program and see the results! – Martin Lauridsen Jul 05 '10 at 15:03