This commit is contained in:
2026-01-19 01:06:45 -06:00
parent 5271688dd4
commit cbf99295da
16 changed files with 69 additions and 121 deletions

View File

@@ -43,10 +43,11 @@ for (var i = 0; i < 100; i++) {
// Calculate statistics
function getStats(arr) {
def avg = reduce(arr, (a,b) => a+b, 0) / length(arr)
def min = min(...arr);
def max = max(...arr);
return { avg, min, max };
return {
avg: reduce(arr, (a,b) => a+b, 0) / length(arr),
min: reduce(arr, min),
max: reduce(arr, max)
};
}
// Pretty print results

View File

@@ -79,18 +79,13 @@ log.console("Wota Encode/Decode Benchmark");
log.console("===================\n");
// We'll run each benchmark scenario in turn.
for (var bench of benchmarks) {
// We'll measure how long it takes to do 'iterations' *for each test value*
// in bench.data. The total loop count is `bench.iterations * bench.data)`.
// Then we compute an overall encode+decode throughput (ops/s).
var totalIterations = bench.iterations * bench.data);
arrfor(benchmarks, function(bench) {
var totalIterations = bench.iterations * length(bench.data);
// We'll define a function that does a roundTrip for *each* data item in bench.data
// to measure in one loop iteration. Then we multiply by bench.iterations.
function runAllData() {
for (var val of bench.data) {
roundTripWota(val);
}
arrfor(bench.data, roundTripWota)
}
var elapsedSec = measureTime(runAllData, bench.iterations);
@@ -100,7 +95,7 @@ for (var bench of benchmarks) {
log.console(` Iterations: ${bench.iterations} × ${length(bench.data)} data items = ${totalIterations}`);
log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`);
log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
}
})
// All done
log.console("Benchmark completed.\n");

View File

@@ -149,11 +149,7 @@ function runBenchmarkForLibrary(lib, bench) {
// 2) Measure DECODING
var decodeTime = measureTime(() => {
for (var i = 0; i < bench.iterations; i++) {
// decode everything we stored during the first iteration
for (var e of encodedList) {
var decoded = lib.decode(e);
// not verifying correctness here, just measuring speed
}
arrfor(encodedList, lib.decode)
}
});