2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-03-04 15:45:24 -05:00
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
// v8 builtin that's close to the upper bound non-NOPs
|
|
|
|
Deno.bench("date_now", { n: 5e5 }, () => {
|
|
|
|
Date.now();
|
|
|
|
});
|
|
|
|
|
2024-02-05 19:05:05 -05:00
|
|
|
function addJS(a, b) {
|
|
|
|
return a + b;
|
2022-08-21 08:07:53 -04:00
|
|
|
}
|
2024-02-05 19:05:05 -05:00
|
|
|
Deno.bench("add_js", () => addJS(1, 2));
|
2022-08-21 08:07:53 -04:00
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
// A very lightweight op, that should be highly optimizable
|
|
|
|
Deno.bench("perf_now", { n: 5e5 }, () => {
|
|
|
|
performance.now();
|
|
|
|
});
|
|
|
|
|
2022-08-19 06:24:40 -04:00
|
|
|
Deno.bench("open_file_sync", () => {
|
2024-01-21 18:20:59 -05:00
|
|
|
using _file = Deno.openSync("./cli/bench/testdata/128k.bin");
|
2022-08-19 06:24:40 -04:00
|
|
|
});
|
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
// A common "language feature", that should be fast
|
|
|
|
// also a decent representation of a non-trivial JSON-op
|
|
|
|
{
|
|
|
|
let i = 0;
|
|
|
|
Deno.bench("url_parse", { n: 5e4 }, () => {
|
2021-03-26 09:13:53 -04:00
|
|
|
new URL(`http://www.google.com/${i}`);
|
2022-07-04 07:23:02 -04:00
|
|
|
i++;
|
2021-03-26 09:13:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
Deno.bench("blob_text_large", { n: 100 }, () => {
|
|
|
|
new Blob([input]).text();
|
|
|
|
});
|
2022-03-16 03:28:38 -04:00
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
const input = "long-string".repeat(99999);
|
|
|
|
Deno.bench("b64_rt_long", { n: 100 }, () => {
|
|
|
|
atob(btoa(input));
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.bench("b64_rt_short", { n: 1e6 }, () => {
|
|
|
|
atob(btoa("123"));
|
|
|
|
});
|
2021-03-28 19:12:19 -04:00
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
{
|
|
|
|
const buf = new Uint8Array(100);
|
|
|
|
const file = Deno.openSync("/dev/zero");
|
|
|
|
Deno.bench("read_zero", { n: 5e5 }, () => {
|
|
|
|
Deno.readSync(file.rid, buf);
|
2021-03-26 09:13:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
{
|
2021-03-26 09:13:53 -04:00
|
|
|
// Not too large since we want to measure op-overhead not sys IO
|
|
|
|
const dataChunk = new Uint8Array(100);
|
|
|
|
const file = Deno.openSync("/dev/null", { write: true });
|
2022-07-04 07:23:02 -04:00
|
|
|
Deno.bench("write_null", { n: 5e5 }, () => {
|
2021-03-26 09:13:53 -04:00
|
|
|
Deno.writeSync(file.rid, dataChunk);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
Deno.bench(
|
|
|
|
"read_128k",
|
|
|
|
{ n: 5e4 },
|
|
|
|
() => Deno.readFile("./cli/bench/testdata/128k.bin"),
|
|
|
|
);
|
2021-03-26 09:13:53 -04:00
|
|
|
|
2022-07-04 07:23:02 -04:00
|
|
|
Deno.bench("request_new", { n: 5e5 }, () => new Request("https://deno.land"));
|