]> git.sesse.net Git - interpreter_trials/commitdiff
Interpreter1 in benchmark framework
authorRune Holm <rune.holm@arm.com>
Wed, 16 Jun 2021 21:22:54 +0000 (23:22 +0200)
committerRune Holm <rune.holm@arm.com>
Wed, 16 Jun 2021 21:29:53 +0000 (23:29 +0200)
interpreter_trials.cpp

index d1183f2c335c6179791f4401f5af9ca50b3b1124..992a77597f2cb41d00e6c3e57397423effa1fa71 100644 (file)
@@ -1,18 +1,32 @@
 #include <benchmark/benchmark.h>
+#include <iostream>
 
-static void BM_StringCreation(benchmark::State& state) {
-  for (auto _ : state)
-    std::string empty_string;
+#include "bytecode.h"
+#include "interpreter.h"
+
+
+template<typename RunLoop>
+void run(RunLoop run_loop)
+{
+    auto [res, cycles] = run_loop(fibonacci, 46);
+    if(res != 1836311903)
+    {
+        throw std::runtime_error("Invalid result " + std::to_string(res));
+    }
+    if(cycles != 480)
+    {
+        throw std::runtime_error("Invalid cycle count " + std::to_string(cycles));
+
+    }
 }
-// Register the function as a benchmark
-BENCHMARK(BM_StringCreation);
 
 // Define another benchmark
-static void BM_StringCopy(benchmark::State& state) {
-  std::string x = "hello";
-  for (auto _ : state)
-    std::string copy(x);
+static void interpreter1_fibonacci(benchmark::State& state) {
+    for (auto _ : state)
+    {
+        run(interpreter1::interpreter1_run);
+    }
 }
-BENCHMARK(BM_StringCopy);
+BENCHMARK(interpreter1_fibonacci);
 
 BENCHMARK_MAIN();