From c2838b62427c7d8bf7f8d1a695564c6e8ed39f81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Tue, 1 Nov 2022 11:02:07 +0000
Subject: [PATCH] feat: new default benchmark values

---
 examples/web/index.ts      | 9 +++++----
 examples/web/react/app.tsx | 6 +++++-
 src/cpu.rs                 | 3 ++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/examples/web/index.ts b/examples/web/index.ts
index bc44e844..60dc960d 100644
--- a/examples/web/index.ts
+++ b/examples/web/index.ts
@@ -541,19 +541,20 @@ class GameboyEmulator extends Observable implements Emulator {
         this.boot({ engine: null });
     }
 
-    benchmark() {
+    benchmark(count = 50000000) {
+        let cycles = 0;
         this.pause();
         try {
             const initial = Date.now();
-            const count = 500000000;
             for (let i = 0; i < count; i++) {
-                this.gameBoy!.clock();
+                cycles += this.gameBoy!.clock();
             }
             const delta = (Date.now() - initial) / 1000;
-            const frequency_mhz = count / delta / 1000 / 1000;
+            const frequency_mhz = cycles / delta / 1000 / 1000;
             return {
                 delta: delta,
                 count: count,
+                cycles: cycles,
                 frequency_mhz: frequency_mhz
             };
         } finally {
diff --git a/examples/web/react/app.tsx b/examples/web/react/app.tsx
index e37d6400..4462d92d 100644
--- a/examples/web/react/app.tsx
+++ b/examples/web/react/app.tsx
@@ -61,6 +61,7 @@ export type RomInfo = {
 export type BenchmarkResult = {
     delta: number;
     count: number;
+    cycles: number;
     frequency_mhz: number;
 };
 
@@ -178,9 +179,12 @@ export interface Emulator extends ObservableI {
      * Runs a benchmark operation in the emulator, effectively
      * measuring the performance of it.
      *
+     * @param count The number of benchmark iterations to be
+     * run, increasing this value will make the benchmark take
+     * more time to be executed.
      * @returns The result metrics from the benchmark run.
      */
-    benchmark(): BenchmarkResult;
+    benchmark(count?: number): BenchmarkResult;
 }
 
 /**
diff --git a/src/cpu.rs b/src/cpu.rs
index 8acb6c0c..e253dba6 100644
--- a/src/cpu.rs
+++ b/src/cpu.rs
@@ -124,7 +124,8 @@ impl Cpu {
         }
 
         if self.ime {
-            // @todo aggregate all of this interrupts in the MMU
+            // @todo aggregate all of this interrupts in the MMU, as there's
+            // a lot of redundant code involved in here
             if (self.mmu.ie & 0x01 == 0x01) && self.mmu.ppu().int_vblank() {
                 debugln!("Going to run V-Blank interrupt handler (0x40)");
 
-- 
GitLab