Closed bognar-dev closed 1 month ago
my guess is that _data
in your first method, and the result of the method call in the second, are being optimised out as unused. you need to used the DoNotOptimize
method to ensure the compiler doesn't drop it.
The Benchmarks are run one after another correct?
If I run the Program with DoNotOptimise and Clobber Memory the results do not not change, Or where do i call it?
class One_BRC : public benchmark::Fixture {
protected:
std::map<std::string, std::vector<float>> _data;
public:
void SetUp(::benchmark::State &state) {
benchmark::DoNotOptimize(_data);
}
void TearDown(::benchmark::State &state) {
}
};
BENCHMARK_F(One_BRC, readFile)(benchmark::State &st) {
for (auto _: st) {
_data = readFile();
benchmark::DoNotOptimize(_data);
benchmark::ClobberMemory();
}
}
BENCHMARK_F(One_BRC, calculateAverages)(benchmark::State &st) {
for (auto _: st) {
calcAvr(_data);
benchmark::DoNotOptimize(_data);
benchmark::ClobberMemory();
}
}
BENCHMARK_MAIN();
the fixture is not persistent between the benchmarks. so _data that is written in the first is empty in the second.
I don't know if its stupid what I did but when I defined data outside the class it seems to work:
std::map<std::string, std::vector<float>> _data;
class One_BRC : public benchmark::Fixture {
protected:
public:
void SetUp(::benchmark::State &state) {
}
void TearDown(::benchmark::State &state) {
}
};
BENCHMARK_DEFINE_F(One_BRC, readFile)(benchmark::State &st) {
for (auto _: st) {
_data = readFile();
benchmark::DoNotOptimize(_data);
}
}
BENCHMARK_DEFINE_F(One_BRC, calculateAverages)(benchmark::State &st) {
for (auto _: st) {
calcAvr(_data);
}
}
BENCHMARK_REGISTER_F(One_BRC, readFile);
BENCHMARK_REGISTER_F(One_BRC, calculateAverages);
BENCHMARK_MAIN();
Benchmark:
Run on (8 X 2295.62 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x4)
L1 Instruction 64 KiB (x4)
L2 Unified 512 KiB (x4)
L3 Unified 4096 KiB (x1)
Load Average: 0.27, 0.15, 0.10
--------------------------------------------------------------------
Benchmark Time CPU Iterations
--------------------------------------------------------------------
One_BRC/readFile 1675013 ns 1340255 ns 452
One_BRC/calculateAverages 2292709 ns 295267 ns 2323
Describe the bug
When I run my Google Benchmarking the Results seem off. The iteration cout for one of the test fixutres is overflowing I think so instead of 1 iteration it shows 4046608 for calculateAverages and only 1 for readFile. I am expecting to see both Benchmarks to show a iteration count of 1. I am not using any recursion or multiple calls in my calculateAverage function so I am surprised to see these Results.
When I time the programm manually like:
My Calculation time is around 1.8 seconds and if I run it with goole benchmark then i get:
This doesn't seem correct I tried it with milliseconds but it doenst change anything. System Which OS, compiler, and compiler version are you using:
To reproduce Steps to reproduce the behavior:
My Benchmark Suite:
Console Output:
Expected behavior Both iteration counters showing 1.
Additional context Here are both of my functions, these are written poorly becuase I wanted a naive benchmark to start with my Billion row challenge.