Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanation of the benchmark results #397

Closed
zack-snyder opened this issue Jun 2, 2017 · 12 comments
Closed

Explanation of the benchmark results #397

zack-snyder opened this issue Jun 2, 2017 · 12 comments

Comments

@zack-snyder
Copy link

Is there an explanation of the standard benchmark table results?

Time: ?
CPU: ?
Iterations: ?

What is this exactly, and didn't find a clear explanation of this in the documentation.
2)
I put a sleep(100) into a while loop with some code.
For unknown reason we got 0ns at the CPU column.
Although there were some code which does some calculation.

 while (state.KeepRunning())
 {
     sleep(100);
     benchmark::DoNotOptimize(some_func());
 }

How big is the time out of all iterations?

static int result = 0;
 while (state.KeepRunning())
 {
     sleep(100);
     std::cout << ++result << std::endl;
 }

He printed till 111 and said iterations: 100
Why?

@EricWF
Copy link
Contributor

EricWF commented Jun 2, 2017

It printed till 111 and said iterations: 100. Why?

Because the benchmark is tested a couple of times with different iteration counts to determine the correct count to use. After it finds an iteration count that causes the benchmark to run for a significant enough period of time it reports only that run, and not the test runs before it.

Resetting result to 0 at the start of the benchmark will show you this.

Is there an explanation of the standard benchmark table results?

Time: The average wall time per iteration.

CPU: The average CPU time per iteration. By default this clock is used when determining the amount of iterations to run. When you sleep your process it is no longer accumulating CPU time. I'm assuming some_func() is almost trivial, and that the compiler optimized almost all of it away. (DoNotOptimize is not magical and needs to be used very carefully. See https://github.com/google/benchmark#preventing-optimisation)

Iterations: The number of iterations the benchmark ran. (See https://github.com/google/benchmark#controlling-number-of-iterations)

Perhaps somebody should add basic documentation about the output information.

@zack-snyder
Copy link
Author

I do some initialization before the loop.
Will this also be included in the measurement?
Something like this:

static void BM_somefunc(benchmark::State& state)
{
    auto foo = do_some_init();
    while (state.KeepRunning())
    {
        do_some_calculation(foo);
    }
}

I get sometimes following results

---------------------------------------------------------
Benchmark                  Time           CPU Iterations
---------------------------------------------------------
BM_fastFuncReturn      16327 ns      16392 ns      44800
BM_slowFuncReturn      17499 ns      16881 ns      40727

You see that the CPU time is in one case higher. How can this be?

@dmah42
Copy link
Member

dmah42 commented Jun 7, 2017 via email

@zack-snyder
Copy link
Author

How can the CPU timer higher, then the wall clock time?
How is the CPU time measured, with ticks?

@werdna87
Copy link

werdna87 commented Jun 9, 2017

I believe there might be a few ways. The most obvious is if your test uses multiple threads

@zack-snyder
Copy link
Author

no, there are no multiple threads involved

@mattreecebentley
Copy link
Contributor

I feel the basic documentation is incredibly sparse and not very detailed about how any of the functions and macros work, their methodology or reasons why they are doing what they're doing. Coming to it afresh having not studied it before, I find it almost impenetrable. I would recommend a full review of the documentation as it stands.

@HaoQChen
Copy link

HaoQChen commented Jul 5, 2020

It printed till 111 and said iterations: 100. Why?

Because the benchmark is tested a couple of times with different iteration counts to determine the correct count to use. After it finds an iteration count that causes the benchmark to run for a significant enough period of time it reports only that run, and not the test runs before it.

Resetting result to 0 at the start of the benchmark will show you this.

Is there an explanation of the standard benchmark table results?

Time: The average wall time per iteration.

CPU: The average CPU time per iteration. By default this clock is used when determining the amount of iterations to run. When you sleep your process it is no longer accumulating CPU time. I'm assuming some_func() is almost trivial, and that the compiler optimized almost all of it away. (DoNotOptimize is not magical and needs to be used very carefully. See https://github.com/google/benchmark#preventing-optimisation)

Iterations: The number of iterations the benchmark ran. (See https://github.com/google/benchmark#controlling-number-of-iterations)

Perhaps somebody should add basic documentation about the output information.

are you sure time is The average wall time per iteration.?

@HaoQChen
Copy link

HaoQChen commented Jul 5, 2020

In linux, it seems to use clock_gettime function to get thread time and process time

see src/timers.cc line 130 and 174

@LebedevRI
Copy link
Collaborator

Regarding documentation, it's a problem or knowledge.
Those who know the answers, know the answers, and don't airlessness think
that some particular thing is missing from the docs/is hard to understand.
Which can of course not be so for new users.

So i think it would be useful if someone could actually comply the list of topics
that seem to be not widely represented in docs, and then someone who can,
would document them.

@GACLove
Copy link

GACLove commented Jan 27, 2021

https://pythonspeed.com/articles/blocking-cpu-or-io/ time and cpu time. May be help you

@dmah42
Copy link
Member

dmah42 commented Apr 27, 2021

closing this out as a specific issue, but i remain open to anyone who wants to enhance the documentation further.

@dmah42 dmah42 closed this as completed Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants