From d8396225c4287c53dd42226266e9f66983125e51 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 28 Aug 2022 12:21:49 +0530 Subject: perf: use fast api for op_now (#15643) --- cli/bench/op_now.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cli/bench/op_now.js (limited to 'cli/bench') diff --git a/cli/bench/op_now.js b/cli/bench/op_now.js new file mode 100644 index 000000000..edce96fed --- /dev/null +++ b/cli/bench/op_now.js @@ -0,0 +1,19 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +const queueMicrotask = globalThis.queueMicrotask || process.nextTick; +let [total, count] = typeof Deno !== "undefined" + ? Deno.args + : [process.argv[2], process.argv[3]]; + +total = total ? parseInt(total, 0) : 50; +count = count ? parseInt(count, 10) : 10000000; + +function bench(fun) { + const start = Date.now(); + for (let i = 0; i < count; i++) fun(); + const elapsed = Date.now() - start; + const rate = Math.floor(count / (elapsed / 1000)); + console.log(`time ${elapsed} ms rate ${rate}`); + if (--total) queueMicrotask(() => bench(fun)); +} + +bench(() => performance.now()); -- cgit v1.2.3