From 9c1288f18889ae3bd10869a9f6ebc53defa3024b Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Wed, 9 Dec 2020 15:46:53 +0200 Subject: perf!: centeral timekeeping This should improve performance, especially when running simulations with multiple peripherals. For instance, the demo project now runs at ~322%, up from ~185% in AVR8js 0.13.1. BREAKING CHANGE: `tick()` methods were removed from individual peripherals. You now need to call `cpu.tick()` instead. --- src/utils/test-utils.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/utils/test-utils.ts') diff --git a/src/utils/test-utils.ts b/src/utils/test-utils.ts index 2bec178..4b2efff 100644 --- a/src/utils/test-utils.ts +++ b/src/utils/test-utils.ts @@ -13,33 +13,29 @@ export function asmProgram(source: string) { } export class TestProgramRunner { - constructor( - private readonly cpu: CPU, - private readonly peripheral: { tick: () => void }, - private readonly onBreak?: (cpu: CPU) => void - ) {} + constructor(private readonly cpu: CPU, private readonly onBreak?: (cpu: CPU) => void) {} runInstructions(count: number) { - const { cpu, peripheral, onBreak } = this; + const { cpu, onBreak } = this; for (let i = 0; i < count; i++) { if (cpu.progMem[cpu.pc] === BREAK_OPCODE) { onBreak?.(cpu); throw new Error('BREAK instruction encountered'); } avrInstruction(cpu); - peripheral.tick(); + cpu.tick(); } } runToBreak(maxIterations = 5000) { - const { cpu, peripheral, onBreak } = this; + const { cpu, onBreak } = this; for (let i = 0; i < maxIterations; i++) { if (cpu.progMem[cpu.pc] === BREAK_OPCODE) { onBreak?.(cpu); return; } avrInstruction(cpu); - peripheral.tick(); + cpu.tick(); } throw new Error('Program ran for too long without a BREAK instruction'); } -- cgit v1.2.3