benchmarking module 4 deno
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.appveyor.yml benching Feb 6, 2019
.travis.yml benching Feb 6, 2019
license.md benching Feb 6, 2019
mod.ts
readme.md fix: API inconsistency Feb 10, 2019
test.ts parallel Feb 14, 2019

readme.md

benching

Travis AppVeyor


Bike-shed benchmarking module. Provides flintstone millisecond resolution.


Import

import * as benching from "https://deno.land/x/benching/mod.ts";

Usage

import {
  BenchmarkTimer,
  runBenchmarks,
  benchmark
} from "https://deno.land/x/benching/mod.ts";

// Simple
benchmark(function forIncrementX1e9(b: BenchmarkTimer) {
  b.start();
  for (let i = 0; i < 1e9; i++);
  b.stop();
});

// Reporting average measured time for $runs runs of func
benchmark({
  name: "runs100ForIncrementX1e6",
  runs: 100,
  func(b: BenchmarkTimer) {
    b.start();
    for (let i: number = 0; i < 1e6; i++);
    b.stop();
  }
});

// Itsabug
benchmark(function throwing(b) {
  b.start();
});

// Bench control
runBenchmarks({ skip: /throw/ });

API

benchmark(bench: BenchmarkDefinition | BenchmarkFunction): void

Register a benchmark that will be run once runBenchmarks is called.

runBenchmarks(opts?: BenchmarkRunOptions): Promise<void>

Run all registered benchmarks serially. Filtering can be applied by setting BenchmarkRunOptions.only and/or BenchmarkRunOptions.skip to regular expressions matching benchmark names.

Other exports

export interface BenchmarkTimer {
  start: () => void;
  stop: () => void;
}

export type BenchmarkFunction = {
  (b: BenchmarkTimer): void | Promise<void>;
  name: string;
};

export interface BenchmarkDefinition {
  func: BenchmarkFunction;
  name: string;
  runs?: number;
}

export interface BenchmarkRunOptions {
  only?: RegExp;
  skip?: RegExp;
}

License

MIT