From 856a659a1d959e34d4019917602bb1c70923c1f8 Mon Sep 17 00:00:00 2001 From: Kenny Daniel Date: Tue, 27 Feb 2024 13:16:24 -0800 Subject: [PATCH] Sync benchmark --- benchmark.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmark.js b/benchmark.js index 3faefac..d1c93d4 100644 --- a/benchmark.js +++ b/benchmark.js @@ -4,7 +4,7 @@ import { snappyUncompress as uncompressWasm } from './hysnappy.js' const fileSize = 200_000_000 -const compressed = await time(`generate and compress ${fileSize.toLocaleString()}`, async () => { +const compressed = time(`generate and compress ${fileSize.toLocaleString()}`, () => { // Generate input array with random data const input = new Uint8Array(fileSize) for (let i = 0; i < fileSize; i++) { @@ -16,18 +16,18 @@ console.log(`compressed ${fileSize.toLocaleString()} bytes to ${compressed.lengt const output = new Uint8Array(fileSize) -await timeWithStdDev('uncompress wasm', () => uncompressWasm(compressed, output)) +timeWithStdDev('uncompress wasm', () => uncompressWasm(compressed, output)) -// await time('uncompress snappyjs', () => uncompress(compressed, output)) +// time('uncompress snappyjs', () => uncompress(compressed, output)) /** * @param {string} name - * @param {() => Promise} fn - * @returns {Promise} + * @param {() => any} fn + * @returns {any} */ -async function time(name, fn) { +function time(name, fn) { const start = performance.now() - const output = await fn() + const output = fn() const ms = performance.now() - start console.log(`${name} took ${ms} ms`) return output @@ -35,14 +35,14 @@ async function time(name, fn) { /** * @param {string} name - * @param {() => Promise} fn + * @param {() => void} fn * @param {number} iterations */ -async function timeWithStdDev(name, fn, iterations = 20) { +function timeWithStdDev(name, fn, iterations = 20) { const times = [] for (let i = 0; i < iterations; i++) { const start = performance.now() - await fn() + fn() const ms = performance.now() - start times.push(ms) }