From 999bdf71ff629cc0e02c333ef5064e4c52a908ca Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 18 Feb 2019 00:54:02 +0000 Subject: [PATCH] Add some basic runtime timings to the 6502 TestHarness class. Signed-off-by: Adrian Conlon --- M6502/M6502.Test/Program.cs | 6 ++++-- M6502/M6502.Test/TestHarness.cs | 38 ++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/M6502/M6502.Test/Program.cs b/M6502/M6502.Test/Program.cs index de701ea..5da7478 100644 --- a/M6502/M6502.Test/Program.cs +++ b/M6502/M6502.Test/Program.cs @@ -12,8 +12,10 @@ namespace M6502.Test ////configuration.DebugMode = true; - var harness = new TestHarness(configuration); - harness.Run(); + using (var harness = new TestHarness(configuration)) + { + harness.Run(); + } } } } diff --git a/M6502/M6502.Test/TestHarness.cs b/M6502/M6502.Test/TestHarness.cs index 3d7cdf1..3e37e89 100644 --- a/M6502/M6502.Test/TestHarness.cs +++ b/M6502/M6502.Test/TestHarness.cs @@ -4,15 +4,29 @@ namespace M6502.Test { - internal class TestHarness + using System; + using System.Diagnostics; + + internal class TestHarness : IDisposable { - private Board board; + private readonly Stopwatch timer = new Stopwatch(); + private readonly Board board; + private long totalCycles = 0; + private long instructions = 0; + + private bool disposed = false; public TestHarness(Configuration configuration) { this.board = new Board(configuration); } + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + public void Run() { this.board.Initialize(); @@ -20,9 +34,27 @@ namespace M6502.Test var cpu = this.board.CPU; + this.timer.Start(); while (cpu.Powered) { - cpu.Step(); + this.totalCycles += cpu.Step(); + ++this.instructions; + } + + this.timer.Stop(); + } + + protected virtual void Dispose(bool disposing) + { + if (!this.disposed) + { + if (disposing) + { + System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles}"); + System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}"); + } + + this.disposed = true; } } }