From 6dc58409c20ee53fbf59c56269735de3b0c75d0c Mon Sep 17 00:00:00 2001 From: Josua Krause Date: Thu, 26 Oct 2023 00:03:23 -0400 Subject: [PATCH] Update bench.html --- bench.html | 229 ++++++++++++++++++++++++++++------------------------- 1 file changed, 122 insertions(+), 107 deletions(-) diff --git a/bench.html b/bench.html index 4371ae9..44529a4 100644 --- a/bench.html +++ b/bench.html @@ -37,6 +37,20 @@ } } + body { + display: flex; + justify-content: center; + } + + h3 { + font-size: 1.25em; + font-weight: 500; + } + + svg { + max-width: 99vw; + } + footer { position: fixed; bottom: 0; @@ -60,116 +74,117 @@ -Run! - - - - - - - - + + var runs = 5; + var res = null; + for(var warm = 0;warm < runs;warm += 1) { + var tmp = doRun(); + if(res && res !== tmp) { + console.warn("inconsistent result"); + return; + } + res = tmp; + } + var time = null; + timer("benchmark"); + for(var warm = 0;warm < runs;warm += 1) { + var finalRes = doRun(); + if(finalRes !== res) { + console.warn("inconsistent end result"); + } + time = timerEnd("benchmark"); + } + span.textContent = (2*runs) + " runs; " + time + "ms avg. per run"; + path.setAttribute("d", finalRes); + }, 100); + } + + function timeNow() { + return window.performance.now(); + } + + var timers = {}; + function timer(name) { + timers[name + '_start'] = timeNow(); + timers[name + '_amount'] = 0; + timers[name + '_sum'] = 0; + timers[name + '_avg'] = 0; + } + + function timerEnd(name) { + var now = timeNow(); + var time = now - timers[name + '_start']; + timers[name + '_start'] = now; + timers[name + '_amount'] += 1; + timers[name + '_sum'] += time; + timers[name + '_avg'] = timers[name + '_sum'] / timers[name + '_amount']; + return timers[name + '_avg']; + } + +