Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Deno.bench

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench({
  name: "example test",
  fn(): void {
    assertEquals("world", "world");
  },
});

Deno.bench({
  name: "example ignored test",
  ignore: Deno.build.os === "windows",
  fn(): void {
    // 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");
  }
});
function bench(t: BenchDefinition): void;
function bench(name: string, fn: () => void | Promise<void>): void;
function bench(fn: () => void | Promise<void>): void;
function bench(
name: string,
options: Omit<BenchDefinition, "fn" | "name">,
fn: () => void | Promise<void>,
): void;
function bench(options: Omit<BenchDefinition, "fn">, fn: () => void | Promise<void>): void;
function bench(options: Omit<BenchDefinition, "fn" | "name">, fn: () => void | Promise<void>): void;
§
bench(t: BenchDefinition): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench({
  name: "example test",
  fn(): void {
    assertEquals("world", "world");
  },
});

Deno.bench({
  name: "example ignored test",
  ignore: Deno.build.os === "windows",
  fn(): void {
    // 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");
  }
});

§Return Type

§
bench(name: string, fn: () => void | Promise<void>): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench("My test description", (): void => {
  assertEquals("hello", "hello");
});

Deno.bench("My async test description", async (): Promise<void> => {
  const decoder = new TextDecoder("utf-8");
  const data = await Deno.readFile("hello_world.txt");
  assertEquals(decoder.decode(data), "Hello world");
});

§Parameters

§
name: string
[src]
§
fn: () => void | Promise<void>
[src]

§Return Type

§
bench(fn: () => void | Promise<void>): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required. Declared function must have a name.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench(function myTestName(): void {
  assertEquals("hello", "hello");
});

Deno.bench(async function myOtherTestName(): Promise<void> {
  const decoder = new TextDecoder("utf-8");
  const data = await Deno.readFile("hello_world.txt");
  assertEquals(decoder.decode(data), "Hello world");
});

§Parameters

§
fn: () => void | Promise<void>
[src]

§Return Type

§
bench(name: string, options: Omit<BenchDefinition, "fn" | "name">, fn: () => void | Promise<void>): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench("My test description", { permissions: { read: true } }, (): void => {
  assertEquals("hello", "hello");
});

Deno.bench("My async test description", { permissions: { read: false } }, async (): Promise<void> => {
  const decoder = new TextDecoder("utf-8");
  const data = await Deno.readFile("hello_world.txt");
  assertEquals(decoder.decode(data), "Hello world");
});

§Parameters

§
name: string
[src]
§
options: Omit<BenchDefinition, "fn" | "name">
[src]
§
fn: () => void | Promise<void>
[src]

§Return Type

§
bench(options: Omit<BenchDefinition, "fn">, fn: () => void | Promise<void>): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench({ name: "My test description", permissions: { read: true } }, (): void => {
  assertEquals("hello", "hello");
});

Deno.bench({ name: "My async test description", permissions: { read: false } }, async (): Promise<void> => {
  const decoder = new TextDecoder("utf-8");
  const data = await Deno.readFile("hello_world.txt");
  assertEquals(decoder.decode(data), "Hello world");
});

§Parameters

§
options: Omit<BenchDefinition, "fn">
[src]
§
fn: () => void | Promise<void>
[src]

§Return Type

§
bench(options: Omit<BenchDefinition, "fn" | "name">, fn: () => void | Promise<void>): void
[src]

Register a bench which will be run when deno bench is used on the command line and the containing module looks like a bench module. fn can be async if required. Declared function must have a name.

import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";

Deno.bench({ permissions: { read: true } }, function myTestName(): void {
  assertEquals("hello", "hello");
});

Deno.bench({ permissions: { read: false } }, async function myOtherTestName(): Promise<void> {
  const decoder = new TextDecoder("utf-8");
  const data = await Deno.readFile("hello_world.txt");
  assertEquals(decoder.decode(data), "Hello world");
});

§Parameters

§
options: Omit<BenchDefinition, "fn" | "name">
[src]
§
fn: () => void | Promise<void>
[src]

§Return Type