Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the custom counters correctly for the benchmarks (I think) #114

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/benchmark/benchmarks/benchmark.assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace zasm::benchmarks
Program program(MachineMode::AMD64);
Assembler assembler(program);

size_t numInstructions = 0;
for (auto _ : state)
{
state.PauseTiming();
Expand All @@ -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<double>(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Assembler_EmitSingle_0_Operands)->Unit(benchmark::kMicrosecond);

Expand All @@ -34,6 +37,7 @@ namespace zasm::benchmarks
Program program(MachineMode::AMD64);
Assembler assembler(program);

size_t numInstructions = 0;
for (auto _ : state)
{
state.PauseTiming();
Expand All @@ -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<double>(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Assembler_EmitSingle_1_Operands)->Unit(benchmark::kMicrosecond);

Expand All @@ -56,6 +62,7 @@ namespace zasm::benchmarks
Program program(MachineMode::AMD64);
Assembler assembler(program);

size_t numInstructions = 0;
for (auto _ : state)
{
state.PauseTiming();
Expand All @@ -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<double>(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Assembler_EmitSingle_2_Operands)->Unit(benchmark::kMicrosecond);

Expand All @@ -78,6 +87,7 @@ namespace zasm::benchmarks
Program program(MachineMode::AMD64);
Assembler assembler(program);

size_t numInstructions = 0;
for (auto _ : state)
{
state.PauseTiming();
Expand All @@ -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<double>(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Assembler_EmitSingle_3_Operands)->Unit(benchmark::kMicrosecond);

Expand All @@ -100,6 +112,7 @@ namespace zasm::benchmarks
Program program(MachineMode::AMD64);
Assembler assembler(program);

size_t numInstructions = 0;
for (auto _ : state)
{
state.PauseTiming();
Expand All @@ -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<double>(program.size()), benchmark::Counter::kIsIterationInvariantRate,
benchmark::Counter::OneK::kIs1000);
}

state.counters["Instructions"] = benchmark::Counter(
static_cast<double>(numInstructions), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Assembler_EmitAll)->Unit(benchmark::kMillisecond);

Expand Down
9 changes: 6 additions & 3 deletions src/benchmark/benchmarks/benchmark.formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(program.size()), benchmark::Counter::kIsIterationInvariantRate,
benchmark::Counter::OneK::kIs1000);
numNodes += program.size();
}

state.counters["PrintedNodes"] = benchmark::Counter(
static_cast<double>(numNodes), benchmark::Counter::kIsRate, benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_Formatter_Program)->Unit(benchmark::kMillisecond);

Expand Down
9 changes: 7 additions & 2 deletions src/benchmark/benchmarks/benchmark.instructioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,9 +35,12 @@ namespace zasm::benchmarks
benchmark::DoNotOptimize(instrInfo);
}

state.counters["InstructionInfos"] = benchmark::Counter(
static_cast<double>(count), benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::OneK::kIs1000);
numInstructions += count;
}

state.counters["InstructionInfos"] = benchmark::Counter(
static_cast<double>(numInstructions), benchmark::Counter::kIsRate,
benchmark::Counter::OneK::kIs1000);
}
BENCHMARK(BM_InstructionInfo)->Unit(benchmark::kMillisecond);

Expand Down
26 changes: 16 additions & 10 deletions src/benchmark/benchmarks/benchmark.serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ namespace zasm::benchmarks
}
}
BENCHMARK(BM_SerializationBasic)->Unit(benchmark::kMillisecond);

template<int64_t TLabelStep>
static void BM_SerializationWithLabels(benchmark::State& state)

template<int64_t TLabelStep> static void BM_SerializationWithLabels(benchmark::State& state)
{
using namespace zasm::x86;

Program program(MachineMode::AMD64);
Assembler assembler(program);
Serializer serializer;

size_t numBytesEncoded = 0;
size_t numInstructions = 0;

for (auto _ : state)
{
state.PauseTiming();
Expand Down Expand Up @@ -95,16 +97,20 @@ namespace zasm::benchmarks

serializer.serialize(program, 0x00400000);

state.counters["BytesEncoded"] = benchmark::Counter(
static_cast<double>(serializer.getCodeSize()), benchmark::Counter::kIsIterationInvariantRate,
benchmark::Counter::OneK::kIs1024);
state.counters["Instructions"] = benchmark::Counter(
static_cast<double>(count), benchmark::Counter::kIsIterationInvariantRate,
benchmark::Counter::OneK::kIs1000);
numBytesEncoded += serializer.getCodeSize();
numInstructions += count;
}

state.counters["BytesEncoded"] = benchmark::Counter(
static_cast<double>(numBytesEncoded), benchmark::Counter::kIsRate,
benchmark::Counter::OneK::kIs1024);

state.counters["Instructions"] = benchmark::Counter(
static_cast<double>(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);
Expand Down
14 changes: 4 additions & 10 deletions src/benchmark/benchmarks/benchmark.stringpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -75,5 +69,5 @@ namespace zasm::benchmarks
}
}
BENCHMARK(BM_StringPool_GetLength)->DenseRange(0, std::size(TestStrings) - 1);
} // namespace zasm::benchmarks

} // namespace zasm::benchmarks
Loading