mirror of
https://github.com/diasurgical/DevilutionX.git
synced 2026-11-07 09:26:09 -10:00
Benchmark: ``` cmake -S. -Bbuild-reld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON cmake --build build-reld --target crawl_benchmark && build-reld/crawl_benchmark ``` Before: ``` ------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------ BM_Crawl/1 3.53 ns 3.53 ns 198384032 BM_Crawl/4 54.3 ns 54.2 ns 12907171 BM_Crawl/16 733 ns 732 ns 955101 BM_Crawl/20 1142 ns 1141 ns 613766 ``` After: ``` ------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------ BM_Crawl/1 1.36 ns 1.36 ns 453018506 BM_Crawl/4 5.59 ns 5.59 ns 124244505 BM_Crawl/16 102 ns 101 ns 6577269 BM_Crawl/20 147 ns 147 ns 4684004 ```
26 lines
516 B
C++
26 lines
516 B
C++
#include <benchmark/benchmark.h>
|
|
|
|
#include "crawl.hpp"
|
|
#include "engine/displacement.hpp"
|
|
|
|
namespace devilution {
|
|
namespace {
|
|
|
|
void BM_Crawl(benchmark::State &state)
|
|
{
|
|
const int radius = static_cast<int>(state.range(0));
|
|
for (auto _ : state) {
|
|
int sum;
|
|
Crawl(0, radius, [&sum](Displacement d) {
|
|
sum += d.deltaX + d.deltaY;
|
|
return false;
|
|
});
|
|
benchmark::DoNotOptimize(sum);
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_Crawl)->RangeMultiplier(4)->Range(1, 20);
|
|
|
|
} // namespace
|
|
} // namespace devilution
|