Skip to main content
Module

x/pretty_benching/pretty_benchmark_history.ts>prettyBenchmarkHistory

:sauropod: A small lib to make your Deno benchmarking progress and results look pretty
Latest
class prettyBenchmarkHistory
import { prettyBenchmarkHistory } from "https://deno.land/x/pretty_benching@v0.3.3/pretty_benchmark_history.ts";

Handles and enforces the set rules on the historic benchmarking data.

Typical usage:

 // add benches, then

 let historicData;
 try {
     historicData = JSON.parse(Deno.readTextFileSync("./benchmarks/history.json"));
 } catch {
     // Decide whether you want to proceed with no history
     console.warn("⚠ cant read history file");
 }

 const history = new prettyBenchmarkHistory(historicData, {
     //options
 });

 runBenchmarks().then((results: BenchmarkRunResult) => {
     history.addResults(results);
     Deno.writeTextFileSync("./benchmarks/history.json", history.getDataString());
 });

Note

The saving and loading of the generated data is the user's responsibility, this class is not doing any file handling. See examples for more info.

Constructors

new
prettyBenchmarkHistory(previousData?: BenchmarkHistory<T, K>, options?: prettyBenchmarkHistoryOptions<T, K>)

Type Parameters

optional
T = unknown
optional
K = unknown

Properties

private
data: BenchmarkHistory<T, K>
private
optional
options: prettyBenchmarkHistoryOptions<T, K>

Methods

private
init()
private
load(previousData: BenchmarkHistory<T, K>)
addResults(runResults: BenchmarkRunResult, options?: { id?: string; date?: Date | string; })

Stores the run's result into the historic data, enforces all set rules on the results.

Returns every benchmark's name that is in the historic data.

Returns a copy of the historic data.

Returns the historic data in a pretty-printed JSON string

Calculates deltas for given BenchmarkResult for each provided property key.

Keys are either measuredRunsAvgMs, totalMs or point to number properties of the calculated extras. Error is thrown, when a key points to a non number property. No delta is calculated for key's which are not present in the extras

Returns false when there is no history for the given benchmark.

getDeltasFrom(results: BenchmarkRunResult, keys?: DeltaKey<T>[]): { [key: string]: { [key: string]: Delta; }; }

Calculates deltas for each benchmark in the provided BenchmarkRunResult for each provided property key.

Keys are either measuredRunsAvgMs, totalMs or point to number properties of the calculated extras. Error is thrown, when a key points to a non number property. No delta is calculated for key's which are not present in the extras

Returns false for a given benchmark when there is no history for it.