aboutsummaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
Diffstat (limited to 'bench')
-rw-r--r--bench/hot-module-reloading/css-stress-test/color-looper.emotion.zig26
-rw-r--r--bench/hot-module-reloading/css-stress-test/color-looper.zig26
-rw-r--r--bench/snippets/base64-buffer-to-string.mjs14
-rw-r--r--bench/snippets/crypto.mjs12
-rw-r--r--bench/snippets/process-info.mjs33
-rw-r--r--bench/snippets/readfile-not-found.mjs17
-rw-r--r--bench/snippets/util-deprecate.mjs60
7 files changed, 155 insertions, 33 deletions
diff --git a/bench/hot-module-reloading/css-stress-test/color-looper.emotion.zig b/bench/hot-module-reloading/css-stress-test/color-looper.emotion.zig
index 9b7a83cf3..02ab05c54 100644
--- a/bench/hot-module-reloading/css-stress-test/color-looper.emotion.zig
+++ b/bench/hot-module-reloading/css-stress-test/color-looper.emotion.zig
@@ -128,27 +128,27 @@ pub fn main() anyerror!void {
counters[counter].timestamp = @truncate(u64, @intCast(u128, std.time.nanoTimestamp()) / (std.time.ns_per_ms / 10));
counters[counter].rotate = rotate % 360;
counters[counter].percent = std.math.mod(f64, std.math.round(((progress_bar + 1.0) / destination_count) * 1000) / 1000, 100) catch 0;
- counters[counter].color_values[0] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[1] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[2] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[0] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[1] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[2] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][2] + 1) % 256)) * 0.8));
counters[counter].color_values[3] = (colors[0][0] + 1) % 256;
counters[counter].color_values[4] = (colors[0][1] + 1) % 256;
counters[counter].color_values[5] = (colors[0][2] + 1) % 256;
- counters[counter].color_values[6] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[7] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[8] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[6] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[7] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[8] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][2] + 1) % 256)) * 0.8));
counters[counter].color_values[9] = (colors[1][0] + 1) % 256;
counters[counter].color_values[10] = (colors[1][1] + 1) % 256;
counters[counter].color_values[11] = (colors[1][2] + 1) % 256;
- counters[counter].color_values[12] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[13] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[14] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[12] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[13] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[14] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][2] + 1) % 256)) * 0.8));
counters[counter].color_values[15] = (colors[2][0] + 1) % 256;
counters[counter].color_values[16] = (colors[2][1] + 1) % 256;
counters[counter].color_values[17] = (colors[2][2] + 1) % 256;
- counters[counter].color_values[18] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[19] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[20] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[18] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[19] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[20] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][2] + 1) % 256)) * 0.8));
counters[counter].color_values[21] = (colors[3][0] + 1) % 256;
counters[counter].color_values[22] = (colors[3][1] + 1) % 256;
counters[counter].color_values[23] = (colors[3][2] + 1) % 256;
@@ -203,7 +203,7 @@ pub fn main() anyerror!void {
_ = try recorder.wait();
all_timestamps[0] = wrote.len;
- for (counters) |count, i| {
+ for (counters, 0..) |count, i| {
all_timestamps[i + 1] = count.timestamp;
}
diff --git a/bench/hot-module-reloading/css-stress-test/color-looper.zig b/bench/hot-module-reloading/css-stress-test/color-looper.zig
index 87f08d32f..0509a525b 100644
--- a/bench/hot-module-reloading/css-stress-test/color-looper.zig
+++ b/bench/hot-module-reloading/css-stress-test/color-looper.zig
@@ -115,27 +115,27 @@ pub fn main() anyerror!void {
counters[counter].timestamp = @truncate(u64, @intCast(u128, std.time.nanoTimestamp()) / (std.time.ns_per_ms / 10));
counters[counter].rotate = rotate % 360;
counters[counter].percent = std.math.mod(f64, std.math.round(((progress_bar + 1.0) / destination_count) * 1000) / 1000, 100) catch 0;
- counters[counter].color_values[0] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[1] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[2] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[0] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[1] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[2] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[0][2] + 1) % 256)) * 0.8));
counters[counter].color_values[3] = (colors[0][0] + 1) % 256;
counters[counter].color_values[4] = (colors[0][1] + 1) % 256;
counters[counter].color_values[5] = (colors[0][2] + 1) % 256;
- counters[counter].color_values[6] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[7] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[8] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[6] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[7] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[8] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[1][2] + 1) % 256)) * 0.8));
counters[counter].color_values[9] = (colors[1][0] + 1) % 256;
counters[counter].color_values[10] = (colors[1][1] + 1) % 256;
counters[counter].color_values[11] = (colors[1][2] + 1) % 256;
- counters[counter].color_values[12] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[13] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[14] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[12] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[13] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[14] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[2][2] + 1) % 256)) * 0.8));
counters[counter].color_values[15] = (colors[2][0] + 1) % 256;
counters[counter].color_values[16] = (colors[2][1] + 1) % 256;
counters[counter].color_values[17] = (colors[2][2] + 1) % 256;
- counters[counter].color_values[18] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][0] + 1) % 256)) * 0.8));
- counters[counter].color_values[19] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][1] + 1) % 256)) * 0.8));
- counters[counter].color_values[20] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][2] + 1) % 256)) * 0.8));
+ counters[counter].color_values[18] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][0] + 1) % 256)) * 0.8));
+ counters[counter].color_values[19] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][1] + 1) % 256)) * 0.8));
+ counters[counter].color_values[20] = @intFromFloat(u32, std.math.round(@floatFromInt(f64, ((colors[3][2] + 1) % 256)) * 0.8));
counters[counter].color_values[21] = (colors[3][0] + 1) % 256;
counters[counter].color_values[22] = (colors[3][1] + 1) % 256;
counters[counter].color_values[23] = (colors[3][2] + 1) % 256;
@@ -190,7 +190,7 @@ pub fn main() anyerror!void {
_ = try recorder.wait();
all_timestamps[0] = wrote.len;
- for (counters) |count, i| {
+ for (counters, 0..) |count, i| {
all_timestamps[i + 1] = count.timestamp;
}
diff --git a/bench/snippets/base64-buffer-to-string.mjs b/bench/snippets/base64-buffer-to-string.mjs
new file mode 100644
index 000000000..a62b76379
--- /dev/null
+++ b/bench/snippets/base64-buffer-to-string.mjs
@@ -0,0 +1,14 @@
+import { bench, run } from "./runner.mjs";
+import { Buffer } from "node:buffer";
+
+const bigBuffer = Buffer.from("hello world".repeat(10000));
+const converted = bigBuffer.toString("base64");
+bench("Buffer.toString('base64')", () => {
+ return bigBuffer.toString("base64");
+});
+
+// bench("Buffer.from(str, 'base64')", () => {
+// return Buffer.from(converted, "base64");
+// });
+
+await run();
diff --git a/bench/snippets/crypto.mjs b/bench/snippets/crypto.mjs
index b0b992a0f..484a4295d 100644
--- a/bench/snippets/crypto.mjs
+++ b/bench/snippets/crypto.mjs
@@ -1,12 +1,6 @@
// so it can run in environments without node module resolution
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
-
-var crypto = globalThis.crypto;
-
-if (!crypto) {
- crypto = await import("node:crypto");
-}
-
+import crypto from "node:crypto";
var foo = new Uint8Array(65536);
bench("crypto.getRandomValues(65536)", () => {
crypto.getRandomValues(foo);
@@ -22,4 +16,8 @@ bench("crypto.randomUUID()", () => {
return crypto.randomUUID()[2];
});
+bench("crypto.randomInt()", () => {
+ return crypto.randomInt(0, 100);
+});
+
await run();
diff --git a/bench/snippets/process-info.mjs b/bench/snippets/process-info.mjs
new file mode 100644
index 000000000..0366472e5
--- /dev/null
+++ b/bench/snippets/process-info.mjs
@@ -0,0 +1,33 @@
+import { bench, run } from "./runner.mjs";
+import { performance } from "perf_hooks";
+
+bench("process.memoryUsage()", () => {
+ process.memoryUsage();
+});
+
+bench("process.memoryUsage.rss()", () => {
+ process.memoryUsage.rss();
+});
+
+bench("process.cpuUsage()", () => {
+ process.cpuUsage();
+});
+
+const init = process.cpuUsage();
+bench("process.cpuUsage(delta)", () => {
+ process.cpuUsage(init);
+});
+
+bench("performance.now()", () => {
+ performance.now();
+});
+
+bench("process.hrtime()", () => {
+ process.hrtime();
+});
+
+bench("process.hrtime.bigint()", () => {
+ process.hrtime.bigint();
+});
+
+await run();
diff --git a/bench/snippets/readfile-not-found.mjs b/bench/snippets/readfile-not-found.mjs
new file mode 100644
index 000000000..c28100ba4
--- /dev/null
+++ b/bench/snippets/readfile-not-found.mjs
@@ -0,0 +1,17 @@
+import { bench, run } from "./runner.mjs";
+import { readFileSync, existsSync } from "node:fs";
+import { readFile } from "node:fs/promises";
+
+bench(`readFileSync(/tmp/404-not-found)`, () => {
+ try {
+ readFileSync("/tmp/404-not-found");
+ } catch (e) {}
+});
+
+bench(`readFile(/tmp/404-not-found)`, async () => {
+ try {
+ await readFile("/tmp/404-not-found");
+ } catch (e) {}
+});
+
+await run();
diff --git a/bench/snippets/util-deprecate.mjs b/bench/snippets/util-deprecate.mjs
new file mode 100644
index 000000000..364601d79
--- /dev/null
+++ b/bench/snippets/util-deprecate.mjs
@@ -0,0 +1,60 @@
+import { bench, run } from "./runner.mjs";
+function deprecateUsingClosure(fn, msg, code) {
+ if (process.noDeprecation === true) {
+ return fn;
+ }
+
+ var realFn = fn;
+ var wrapper = () => {
+ return fnToWrap.apply(this, arguments);
+ };
+
+ var deprecater = () => {
+ if (process.throwDeprecation) {
+ var err = new Error(msg);
+ if (code) err.code = code;
+ throw err;
+ } else if (process.traceDeprecation) {
+ console.trace(msg);
+ } else {
+ console.error(msg);
+ }
+
+ fnToWrap = realFn;
+ return realFn.apply(this, arguments);
+ };
+ var fnToWrap = deprecater;
+
+ return wrapper;
+}
+
+function deprecateOriginal(fn, msg) {
+ var warned = false;
+ function deprecated() {
+ if (!warned) {
+ if (process.throwDeprecation) {
+ throw new Error(msg);
+ } else if (process.traceDeprecation) {
+ console.trace(msg);
+ } else {
+ console.error(msg);
+ }
+ warned = true;
+ }
+ return fn.apply(this, arguments);
+ }
+ return deprecated;
+}
+
+const deprecatedy = deprecateUsingClosure(() => {}, "This is deprecated", "DEP0001");
+const deprecatedy2 = deprecateOriginal(() => {}, "This is deprecated");
+
+bench("deprecateUsingClosure", () => {
+ deprecatedy(Math.random() + 1);
+});
+
+bench("deprecateOriginal", () => {
+ deprecatedy2(Math.random() + 1);
+});
+
+await run();