summaryrefslogtreecommitdiff
path: root/tools/bench/rebench.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-01 00:42:24 +0200
committerGitHub <noreply@github.com>2021-10-01 00:42:24 +0200
commitb3ceafaa5dfee4127dff155cf6f4cc210f22ab59 (patch)
treea6c16ed129f70553046030d8ae3c253083187416 /tools/bench/rebench.js
parent6bf5c850e6b4f6163721bd673b191bda0e0dc0a6 (diff)
tools(bench): rebootstrap (#12281)
Enable deno devs to bench/profile/test JS code changes without doing a full --release rebuild. Incremental release builds take ~4mn on M1s, often more on other machines ...
Diffstat (limited to 'tools/bench/rebench.js')
-rw-r--r--tools/bench/rebench.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/bench/rebench.js b/tools/bench/rebench.js
new file mode 100644
index 000000000..bbc5a3c2f
--- /dev/null
+++ b/tools/bench/rebench.js
@@ -0,0 +1,25 @@
+export function benchSync(name, n, innerLoop) {
+ const t1 = Date.now();
+ for (let i = 0; i < n; i++) {
+ innerLoop(i);
+ }
+ const t2 = Date.now();
+ console.log(benchStats(name, n, t1, t2));
+}
+
+export async function benchAsync(name, n, innerLoop) {
+ const t1 = Date.now();
+ for (let i = 0; i < n; i++) {
+ await innerLoop(i);
+ }
+ const t2 = Date.now();
+ console.log(benchStats(name, n, t1, t2));
+}
+
+function benchStats(name, n, t1, t2) {
+ const dt = (t2 - t1) / 1e3;
+ const r = n / dt;
+ const ns = Math.floor(dt / n * 1e9);
+ return `${name}:${" ".repeat(20 - name.length)}\t` +
+ `n = ${n}, dt = ${dt.toFixed(3)}s, r = ${r.toFixed(0)}/s, t = ${ns}ns/op`;
+}