google-benchmark

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

落花浮王杯 提交于 2020-07-28 06:25:11
问题 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 block, but with two arithmetic operations in the for loop body. Here is the code I ended up testing: #include <iostream> #include <chrono> #define NUM_ITERATIONS 100000000 int main() { // Block 1: one operation in loop body { int64_t x = 0, y = 0;

How to build and link google benchmark using cmake in windows

两盒软妹~` 提交于 2020-01-24 20:14:33
问题 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 cmake or cl. the problem I think is that google-benchmark builds the library inside the src folder, i.e it is build in src/Release/benchmark.lib now i cannot point to it in cmake if I use ${benchmark_LIBRARIES} it looks for the library in the Release

Google benchmark code Setup

橙三吉。 提交于 2019-12-13 04:28:55
问题 Given the following code #include <benchmark/benchmark.h> #include <iostream> static void BM_foo(benchmark::State& state) { std::cout << "Foo "<< std::endl; for (auto _: state) { std::cout << state.iterations() << " In loop " <<std::endl; } } BENCHMARK(BM_foo); BENCHMARK_MAIN(); I thought the std::cout << "Foo "<< std::endl; will be executed only once, but during my test, it runs 7 times. So my questions are: How can I run some setup code only once before the benchmark, like "std::cout <<