tags:

views:

111

answers:

1

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]
+2  A: 

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

Mike Dunlavey
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
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