Questions tagged [google-benchmark]

84 questions
15
votes
5 answers

Why is ONE basic arithmetic operation in for loop body executed SLOWER THAN TWO arithmetic operations?

While I experimented with measuring time of execution of arithmetic operations, I came across very strange behavior. A code block containing a for loop with one arithmetic operation in the loop body was always executed slower than an identical code…
Oliort UA
  • 1,568
  • 1
  • 14
  • 31
12
votes
5 answers

How to build and link google benchmark using cmake in windows

I am trying to build google-benchmark and use it with my library using cmake. I have managed to build google-benchmark and run all its tests successfully using cmake. I am unfortunately unable to link it properly with my c++ code in windows using…
mathguy
  • 153
  • 2
  • 8
10
votes
3 answers

How to special-case the number of iterations in google benchmark?

I am aware of the --benchmark_repetitions flag and it is not what I need. I want to be able to specify the number of iterations for one benchmark. I am okay with using a --benchmark_iterations flag which sets the number of iterations for all…
Yixing Liu
  • 2,179
  • 1
  • 20
  • 36
9
votes
3 answers

How to pass arguments to a Google Benchmark Program

I have a C++ Google Benchmark Program. It uses Google's BENCHMARK_MAIN() method. Now I call and execute the compiled program with a Go script. Is there a way to pass arguments into my benchmark program? (I know the common way over a main method, but…
user7035883
8
votes
1 answer

Google Benchmark Frameworks DoNotOptimize

I am a bit confused about the implementation of the function void DoNotOptimize of the Google Benchmark Framework (definition from here): template inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) { asm volatile("" : :…
Hymir
  • 811
  • 1
  • 10
  • 20
7
votes
2 answers

Google benchmark with command line args. Writing my own main function?

I have a code that goes something like: ... void benchMark(benchmark::State& state){ maxCapacity = state.range(0); // set up some stuff for (auto _ : state){ // time this code } } BENCHMARK(benchMark)->DenseRange(2, 10,…
Ankit Kumar
  • 1,145
  • 9
  • 30
5
votes
0 answers

Google Benchmark sorting algorithms

I would like to benchmark various sorting algorithms using Google Benchmark. If I use static void StdSort(benchmark::State& state) { auto v = generate_random_vector(state.range(0)); for (auto _ : state) std::sort(std::begin(v),…
Touloudou
  • 2,079
  • 1
  • 17
  • 28
5
votes
1 answer

Google Benchmark as a cmake dependency

I'm trying to compile a google benchmark with a dependency on the Libtorch (Pytorch) library. I have installed Google Benchmark with make install so to my understanding i should be able to use find_package() to add both dependencies. Finally I add…
yhr
  • 53
  • 2
  • 6
5
votes
1 answer

Google Benchmark Custom Setup And Teardown Method

I am using benchmark library to benchmark some codes. I want to call a setup method before calling the actual benchmark code one time and not to be repeated everytime, for multiple benchmark method calls.. For e.g: static void…
Kishan Kumar
  • 302
  • 8
  • 19
5
votes
1 answer

Explanation for why allocating a second time changes performance

I was testing some micro benchmarks on dense matrix multiplication (as a curiosity), and I noticed some very strange performance results. Here is a minimal working example: #include #include constexpr long long n =…
helloworld922
  • 10,801
  • 5
  • 48
  • 85
4
votes
1 answer

How does Google's `DoNotOptimize()` function enforce statement ordering

I'm trying to understand exactly how Google's DoNotOptimize() is supposed to work. For completeness, here is its definition (for clang, and non-const data): template inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm…
4
votes
2 answers

What happens to the return values while using Google benchmark?

I am benchmarking some functions in our software using the Google-benchmark. Let us say the function signature is something like below. The return type can be any other derived data type. std::map func(Obj& o1, Obj& o2); The…
talekeDskobeDa
  • 372
  • 2
  • 13
4
votes
0 answers

Why does cpu time have usually larger fluctuations than real time in benchmarks?

When examining the output of my benchmarks with the Google Benchmark framework, I observed that the standard deviation of the measured cpu time was in many cases significantly larger than the standard deviation of the measured real time. Why is…
thebrandre
  • 449
  • 4
  • 5
3
votes
1 answer

Reproducing performance results for vector insertion with google benchmark

Recently I saw the following result regarding the insertion of elements into the front of std::list and std::vector: for std::list the time is linear for std::vectorthe time polynomial but for a small number of elements (<800) std::vector beats…
orfvl
  • 111
  • 5
3
votes
1 answer

How pointer chasing is working in this benchmark

Trying to understand how pointer chasing is working (basically the access pattern) in the following benchmark: https://github.com/google/multichase/blob/master/multichase.c For the simple chase: static void chase_simple(per_thread_t *t) { void *p…
Milan
  • 1,447
  • 5
  • 19
  • 27
1
2 3 4 5 6