Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.BenchContext

A modern runtime for JavaScript and TypeScript.
Go to Latest
interface Deno.BenchContext
import { type Deno } from "https://deno.land/x/deno@v1.36.0/cli/tsc/dts/lib.deno.ns.d.ts";
const { BenchContext } = Deno;

Context that is passed to a benchmarked function. The instance is shared between iterations of the benchmark. Its methods can be used for example to override of the measured portion of the function.

Properties

name: string

The current benchmark name.

origin: string

The string URL of the current benchmark.

Methods

start(): void

Restarts the timer for the bench measurement. This should be called after doing setup work which should not be measured.

Deno.bench("foo", async (t) => {
  const data = await Deno.readFile("data.txt");
  t.start();
  // some operation on `data`...
});
end(): void

End the timer early for the bench measurement. This should be called before doing teardown work which should not be measured.

Deno.bench("foo", async (t) => {
  const file = await Deno.open("data.txt");
  t.start();
  // some operation on `file`...
  t.end();
  file.close();
});