import { Deno } from "https://deno.land/x/ayonli_jsext@v0.9.72/lib.deno.d.ts";
const { bench } = Deno;
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench({
name: "example test",
fn() {
assertEquals("world", "world");
},
});
Deno.bench({
name: "example ignored test",
ignore: Deno.build.os === "windows",
fn() {
// This test is ignored only on Windows machines
},
});
Deno.bench({
name: "example async test",
async fn() {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
});
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench("My test description", () => {
assertEquals("hello", "hello");
});
Deno.bench("My async test description", async () => {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
});
Parameters
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench(function myTestName() {
assertEquals("hello", "hello");
});
Deno.bench(async function myOtherTestName() {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
});
Parameters
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench(
"My test description",
{ permissions: { read: true } },
() => {
assertEquals("hello", "hello");
}
);
Deno.bench(
"My async test description",
{ permissions: { read: false } },
async () => {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);
Parameters
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench(
{ name: "My test description", permissions: { read: true } },
() => {
assertEquals("hello", "hello");
}
);
Deno.bench(
{ name: "My async test description", permissions: { read: false } },
async () => {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);
Parameters
Register a benchmark test which will be run when deno bench
is used on
the command line and the containing module looks like a bench module.
If the test function (fn
) returns a promise or is async, the test runner
will await resolution to consider the test complete.
import { assertEquals } from "https://deno.land/std/assert/mod.ts";
Deno.bench(
{ permissions: { read: true } },
function myTestName() {
assertEquals("hello", "hello");
}
);
Deno.bench(
{ permissions: { read: false } },
async function myOtherTestName() {
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);