diff --git a/src/benchmark/benchmarks/benchmark.assembler.cpp b/src/benchmark/benchmarks/benchmark.assembler.cpp index af953f0..0637222 100644 --- a/src/benchmark/benchmarks/benchmark.assembler.cpp +++ b/src/benchmark/benchmarks/benchmark.assembler.cpp @@ -12,6 +12,7 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; for (auto _ : state) { state.PauseTiming(); @@ -21,9 +22,11 @@ namespace zasm::benchmarks assembler.nop(); - state.counters["Instructions"] = benchmark::Counter( - 1.0, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); + numInstructions++; } + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Assembler_EmitSingle_0_Operands)->Unit(benchmark::kMicrosecond); @@ -34,6 +37,7 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; for (auto _ : state) { state.PauseTiming(); @@ -43,9 +47,11 @@ namespace zasm::benchmarks assembler.push(rax); - state.counters["Instructions"] = benchmark::Counter( - 1.0, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); + numInstructions++; } + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Assembler_EmitSingle_1_Operands)->Unit(benchmark::kMicrosecond); @@ -56,6 +62,7 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; for (auto _ : state) { state.PauseTiming(); @@ -65,9 +72,11 @@ namespace zasm::benchmarks assembler.mov(rax, rax); - state.counters["Instructions"] = benchmark::Counter( - 1.0, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); + numInstructions++; } + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Assembler_EmitSingle_2_Operands)->Unit(benchmark::kMicrosecond); @@ -78,6 +87,7 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; for (auto _ : state) { state.PauseTiming(); @@ -87,9 +97,11 @@ namespace zasm::benchmarks assembler.rorx(rcx, rdx, Imm(1)); - state.counters["Instructions"] = benchmark::Counter( - 1.0, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); + numInstructions++; } + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Assembler_EmitSingle_3_Operands)->Unit(benchmark::kMicrosecond); @@ -100,6 +112,7 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; for (auto _ : state) { state.PauseTiming(); @@ -110,12 +123,12 @@ namespace zasm::benchmarks for (const auto& instr : zasm::tests::data::Instructions) { instr.emitter(assembler); + numInstructions++; } - - state.counters["Instructions"] = benchmark::Counter( - static_cast(program.size()), benchmark::Counter::kIsIterationInvariantRate, - benchmark::Counter::OneK::kIs1000); } + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Assembler_EmitAll)->Unit(benchmark::kMillisecond); diff --git a/src/benchmark/benchmarks/benchmark.formatter.cpp b/src/benchmark/benchmarks/benchmark.formatter.cpp index 70a912b..e2987a9 100644 --- a/src/benchmark/benchmarks/benchmark.formatter.cpp +++ b/src/benchmark/benchmarks/benchmark.formatter.cpp @@ -22,15 +22,18 @@ namespace zasm::benchmarks } } + size_t numNodes = 0; + for (auto _ : state) { auto res = formatter::toString(program); benchmark::DoNotOptimize(res); - state.counters["PrintedNodes"] = benchmark::Counter( - static_cast(program.size()), benchmark::Counter::kIsIterationInvariantRate, - benchmark::Counter::OneK::kIs1000); + numNodes += program.size(); } + + state.counters["PrintedNodes"] = benchmark::Counter( + static_cast(numNodes), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_Formatter_Program)->Unit(benchmark::kMillisecond); diff --git a/src/benchmark/benchmarks/benchmark.instructioninfo.cpp b/src/benchmark/benchmarks/benchmark.instructioninfo.cpp index 3d6e19d..cb7f44a 100644 --- a/src/benchmark/benchmarks/benchmark.instructioninfo.cpp +++ b/src/benchmark/benchmarks/benchmark.instructioninfo.cpp @@ -13,6 +13,8 @@ namespace zasm::benchmarks Program program(MachineMode::AMD64); Assembler assembler(program); + size_t numInstructions = 0; + for (auto s : state) { const auto count = std::size(tests::data::Instructions); @@ -33,9 +35,12 @@ namespace zasm::benchmarks benchmark::DoNotOptimize(instrInfo); } - state.counters["InstructionInfos"] = benchmark::Counter( - static_cast(count), benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000); + numInstructions += count; } + + state.counters["InstructionInfos"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, + benchmark::Counter::OneK::kIs1000); } BENCHMARK(BM_InstructionInfo)->Unit(benchmark::kMillisecond); diff --git a/src/benchmark/benchmarks/benchmark.serialization.cpp b/src/benchmark/benchmarks/benchmark.serialization.cpp index 8e5b886..f7e1fdb 100644 --- a/src/benchmark/benchmarks/benchmark.serialization.cpp +++ b/src/benchmark/benchmarks/benchmark.serialization.cpp @@ -53,9 +53,8 @@ namespace zasm::benchmarks } } BENCHMARK(BM_SerializationBasic)->Unit(benchmark::kMillisecond); - - template - static void BM_SerializationWithLabels(benchmark::State& state) + + template static void BM_SerializationWithLabels(benchmark::State& state) { using namespace zasm::x86; @@ -63,6 +62,9 @@ namespace zasm::benchmarks Assembler assembler(program); Serializer serializer; + size_t numBytesEncoded = 0; + size_t numInstructions = 0; + for (auto _ : state) { state.PauseTiming(); @@ -95,16 +97,20 @@ namespace zasm::benchmarks serializer.serialize(program, 0x00400000); - state.counters["BytesEncoded"] = benchmark::Counter( - static_cast(serializer.getCodeSize()), benchmark::Counter::kIsIterationInvariantRate, - benchmark::Counter::OneK::kIs1024); - state.counters["Instructions"] = benchmark::Counter( - static_cast(count), benchmark::Counter::kIsIterationInvariantRate, - benchmark::Counter::OneK::kIs1000); + numBytesEncoded += serializer.getCodeSize(); + numInstructions += count; } + + state.counters["BytesEncoded"] = benchmark::Counter( + static_cast(numBytesEncoded), benchmark::Counter::kIsRate, + benchmark::Counter::OneK::kIs1024); + + state.counters["Instructions"] = benchmark::Counter( + static_cast(numInstructions), benchmark::Counter::kIsRate, + benchmark::Counter::OneK::kIs1000); } BENCHMARK_TEMPLATE(BM_SerializationWithLabels, 128)->Unit(benchmark::kMillisecond); - + BENCHMARK_TEMPLATE(BM_SerializationWithLabels, 64)->Unit(benchmark::kMillisecond); BENCHMARK_TEMPLATE(BM_SerializationWithLabels, 32)->Unit(benchmark::kMillisecond); diff --git a/src/benchmark/benchmarks/benchmark.stringpool.cpp b/src/benchmark/benchmarks/benchmark.stringpool.cpp index 2464eb6..2d82adc 100644 --- a/src/benchmark/benchmarks/benchmark.stringpool.cpp +++ b/src/benchmark/benchmarks/benchmark.stringpool.cpp @@ -3,14 +3,8 @@ namespace zasm::benchmarks { - static const std::string TestStrings[] = - { - "hello", - "world", - "longer string", - "even longer string", - "even longer longer string" - }; + static const std::string TestStrings[] = { "hello", "world", "longer string", "even longer string", + "even longer longer string" }; static void BM_StringPool_Aquire(benchmark::State& state) { @@ -75,5 +69,5 @@ namespace zasm::benchmarks } } BENCHMARK(BM_StringPool_GetLength)->DenseRange(0, std::size(TestStrings) - 1); - -} // namespace zasm::benchmarks \ No newline at end of file + +} // namespace zasm::benchmarks