More straightforward to read test harness results

This commit is contained in:
Adrian Conlon committed 2026-06-14 21:53:56 +01:00
1 parent b64c997f89
commit 25dcb0c4c0
2 files changed
+26 -24

No files matched your search

+25 -23
View File
@@ -6,47 +6,49 @@ namespace EightBit
{
using System.Diagnostics;
public class TestHarness<TBus, TProcessor>(TBus board, TProcessor cpu) where TBus : Bus where TProcessor : Processor
public class TestHarness<TBus, TProcessor>(TBus board, TProcessor cpu, int targetClocksPerSecond = 2_000_000) where TBus : Bus where TProcessor : Processor
{
private readonly Stopwatch _timer = new();
private readonly TBus _board = board;
private readonly TProcessor _cpu = cpu;
private readonly int _targetClocksPerSecond = targetClocksPerSecond;
private long _totalCycles;
private TimeSpan _totalUserProcessorTime;
public long ElapsedMilliseconds => this._timer.ElapsedMilliseconds;
public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f;
public TimeSpan ActualElapsed => TimeSpan.FromMilliseconds(this.ElapsedMilliseconds);
public float CyclesPerSecond => this._totalCycles / this.ElapsedSeconds;
public double CyclesPerSecond => this._totalCycles / this.ActualElapsed.TotalSeconds;
public double ActualClockSpeed => this.CyclesPerSecond / 1_000_000;
public int TargetClocksPerSecond => this._targetClocksPerSecond;
public double TargetClockSpeed => this.TargetClocksPerSecond / 1_000_000;
public long TotalCycles => this._totalCycles;
public TimeSpan TargetElapsed => TimeSpan.FromSeconds(this.TotalCycles / (double)this.TargetClocksPerSecond);
public void Run()
{
using var process = Process.GetCurrentProcess();
this._timer.Start();
this._board.Initialize();
this._board.RaisePOWER();
while (this._cpu.Powered)
{
this._timer.Start();
var startingUsage = process.UserProcessorTime;
this._board.Initialize();
this._board.RaisePOWER();
while (this._cpu.Powered)
{
this._totalCycles += this._cpu.Step();
}
var finishingUsage = process.UserProcessorTime;
this._timer.Stop();
this._totalUserProcessorTime = finishingUsage - startingUsage;
this._totalCycles += this._cpu.Step();
}
this._timer.Stop();
Console.Out.WriteLine();
Console.Out.WriteLine($"Guest cycles = {this._totalCycles:N0}");
Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}");
Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz");
Console.Out.WriteLine($"Processor time = {this._totalUserProcessorTime.TotalSeconds:g}");
Console.Out.WriteLine($"Elapsed time (at {this.ActualClockSpeed:g3}MHz actual) = {this.ActualElapsed}");
Console.Out.WriteLine($"Elapsed time (at {(this.TargetClockSpeed):g3}MHz target) = {this.TargetElapsed}");
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ namespace Z80.Test
#endif
var board = new Board(configuration);
var harness = new TestHarness<Board, Z80>(board, board.CPU);
var harness = new TestHarness<Board, Z80>(board, board.CPU, 4_000_000);
harness.Run();
}
}