Ende.bench
function
function Ende.bench(b: BenchDefinition): voidRegister a benchmark test which will be run when ende bench is used on
the command line and the containing module looks like a bench module.
A module "looks like a bench module" when ende bench selects it for
execution. When you pass explicit file paths to ende bench, those files
are always run. When you run ende bench without paths, it walks the
directory looking for files whose name (ignoring the extension) ends with
_bench or .bench, or is exactly bench. Examples are foo_bench.ts,
foo.bench.js, or bench.ts. Supported extensions are the same as for
tests (.ts, .tsx, .js, .jsx, .mjs, .mts, .cjs, .cts).
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 "jsr:@ende/assert";
Ende.bench({
name: "example test",
fn() {
assertEquals("world", "world");
},
});
Ende.bench({
name: "example ignored test",
ignore: Ende.build.os === "windows",
fn() {
// This test is ignored only on Windows machines
},
});
Ende.bench({
name: "example async test",
async fn() {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
});
function
function Ende.bench(name: string, fn: (b: BenchContext) => void | Promise<void>): voidRegister a benchmark test which will be run when ende 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 "jsr:@ende/assert";
Ende.bench("My test description", () => {
assertEquals("hello", "hello");
});
Ende.bench("My async test description", async () => {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
});
function
function Ende.bench(fn: (b: BenchContext) => void | Promise<void>): voidRegister a benchmark test which will be run when ende 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 "jsr:@ende/assert";
Ende.bench(function myTestName() {
assertEquals("hello", "hello");
});
Ende.bench(async function myOtherTestName() {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
});
function
function Ende.bench(name: string, options: Omit<BenchDefinition, "fn" | "name">, fn: (b: BenchContext) => void | Promise<void>): voidRegister a benchmark test which will be run when ende 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 "jsr:@ende/assert";
Ende.bench(
"My test description",
{ permissions: { read: true } },
() => {
assertEquals("hello", "hello");
}
);
Ende.bench(
"My async test description",
{ permissions: { read: false } },
async () => {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);
function
function Ende.bench(options: Omit<BenchDefinition, "fn">, fn: (b: BenchContext) => void | Promise<void>): voidRegister a benchmark test which will be run when ende 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 "jsr:@ende/assert";
Ende.bench(
{ name: "My test description", permissions: { read: true } },
() => {
assertEquals("hello", "hello");
}
);
Ende.bench(
{ name: "My async test description", permissions: { read: false } },
async () => {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);
function
function Ende.bench(options: Omit<BenchDefinition, "fn" | "name">, fn: (b: BenchContext) => void | Promise<void>): voidRegister a benchmark test which will be run when ende 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 "jsr:@ende/assert";
Ende.bench(
{ permissions: { read: true } },
function myTestName() {
assertEquals("hello", "hello");
}
);
Ende.bench(
{ permissions: { read: false } },
async function myOtherTestName() {
const decoder = new TextDecoder("utf-8");
const data = await Ende.readFile("hello_world.txt");
assertEquals(decoder.decode(data), "Hello world");
}
);