1 #include <benchmark/benchmark.h>
5 #include "interpreter.h"
8 template<typename RunLoop>
9 void run(RunLoop run_loop)
11 auto [res, cycles] = run_loop(fibonacci, 46);
14 throw std::runtime_error("Invalid result " + std::to_string(res));
18 throw std::runtime_error("Invalid cycle count " + std::to_string(cycles));
23 static void interpreter1_baseline(benchmark::State& state) {
26 run(interpreter1::interpreter_run);
29 BENCHMARK(interpreter1_baseline);
31 static void interpreter2_state_as_parameters(benchmark::State& state) {
34 run(interpreter2::interpreter_run);
37 BENCHMARK(interpreter2_state_as_parameters);
39 static void interpreter3_cycle_count_in_op_funs(benchmark::State& state) {
42 run(interpreter3::interpreter_run);
45 BENCHMARK(interpreter3_cycle_count_in_op_funs);
47 static void interpreter4_pc_in_registers(benchmark::State& state) {
50 run(interpreter4::interpreter_run);
53 BENCHMARK(interpreter4_pc_in_registers);
55 static void interpreter5_pc_flags_in_registers(benchmark::State& state) {
58 run(interpreter5::interpreter_run);
61 BENCHMARK(interpreter5_pc_flags_in_registers);
63 static void interpreter6_pc_flags_cycle_count_in_registers(benchmark::State& state) {
66 run(interpreter6::interpreter_run);
69 BENCHMARK(interpreter6_pc_flags_cycle_count_in_registers);
71 static void interpreter7_tail_calls(benchmark::State& state) {
74 run(interpreter7::interpreter_run);
77 BENCHMARK(interpreter7_tail_calls);
79 static void interpreter8_dispatch_table_in_registers(benchmark::State& state) {
82 run(interpreter8::interpreter_run);
85 BENCHMARK(interpreter8_dispatch_table_in_registers);
87 static void interpreter9_separate_flags(benchmark::State& state) {
90 run(interpreter9::interpreter_run);
93 BENCHMARK(interpreter9_separate_flags);
95 static void interpreter10_only_4_parameters(benchmark::State& state) {
98 run(interpreter10::interpreter_run);
101 BENCHMARK(interpreter10_only_4_parameters);
103 static void interpreter11_computed_goto(benchmark::State& state) {
106 run(interpreter11::interpreter_run);
109 BENCHMARK(interpreter11_computed_goto);
111 static void interpreter12_tail_calls_locked_reg(benchmark::State& state) {
114 run(interpreter12::interpreter_run);
117 BENCHMARK(interpreter12_tail_calls_locked_reg);