diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-08-28 12:21:49 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-28 12:21:49 +0530 |
commit | d8396225c4287c53dd42226266e9f66983125e51 (patch) | |
tree | 27516437c40b80596f4d0fc9b821882a0f2a0ca1 /cli/bench/op_now.js | |
parent | 7c4f57e8b091bc386242f83b5373e4bb33382012 (diff) |
perf: use fast api for op_now (#15643)
Diffstat (limited to 'cli/bench/op_now.js')
-rw-r--r-- | cli/bench/op_now.js | 19 |
1 files changed, 19 insertions, 0 deletions
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()); |