Show processor, as well as elapsed time in test harness.

This commit is contained in:
Adrian Conlon 2024-07-08 10:12:33 +01:00
parent b38cabc96d
commit e73d7a52b2

View File

@ -7,16 +7,16 @@ namespace M6502.Test
using System; using System;
using System.Diagnostics; using System.Diagnostics;
internal class TestHarness : IDisposable internal class TestHarness(Configuration configuration) : IDisposable
{ {
private readonly Stopwatch timer = new Stopwatch(); private readonly Process process = Process.GetCurrentProcess();
private readonly Board board; private readonly Stopwatch timer = new();
private readonly Board board = new(configuration);
private long totalCycles = 0; private long totalCycles = 0;
private TimeSpan totalUserProcessorTime;
private bool disposed = false; private bool disposed = false;
public TestHarness(Configuration configuration) => this.board = new Board(configuration);
public void Dispose() public void Dispose()
{ {
this.Dispose(true); this.Dispose(true);
@ -25,18 +25,21 @@ namespace M6502.Test
public void Run() public void Run()
{ {
this.timer.Start();
var startingUsage = this.process.UserProcessorTime;
this.board.Initialize(); this.board.Initialize();
this.board.RaisePOWER(); this.board.RaisePOWER();
var cpu = this.board.CPU; var cpu = this.board.CPU;
this.timer.Start();
while (cpu.Powered) while (cpu.Powered)
{ {
this.totalCycles += cpu.Step(); this.totalCycles += cpu.Step();
} }
var finishingUsage = this.process.UserProcessorTime;
this.timer.Stop(); this.timer.Stop();
this.totalUserProcessorTime = finishingUsage - startingUsage;
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
@ -46,6 +49,7 @@ namespace M6502.Test
if (disposing) if (disposing)
{ {
System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles}"); System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles}");
System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime}");
System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}"); System.Console.Out.WriteLine($"Seconds = {this.timer.ElapsedMilliseconds / 1000.0}");
} }