Library for simple benchmarks in typescript projects.
npm install micro-bench --save-dev
import {Bench} from "micro-bench";
// create bench with 1 million iterations.
let bench = new Bench(() => {
// your code under benchmarking
}, 1000000);
// run code and get results
let result = bench.execute("My benchmark");
console.log(result);
Suitable for make performance tests of some code with one or more data sets — fixtures.
// create bench with 1 million iterations.
let bench = new Bench((value: string|number) => {
// your code under benchmarking
}, 1000000);
// run code and get results
let results: Result[] = [];
results.push(bench.execute("Test with strings", [["foo"], ["bar"], ["baz"]]));
results.push(bench.execute("Test with numbers", [[1], [2], [3]]));
Every fixture is array of arrays, that will be passed as arguments to your_function.apply().
.getCaseName(): string
- return name of case specified onBench.execute()
..getAverageIterationTime(): number
- return average time of iteration in milliseconds..getIterationPerSec(): number
- return number of iterations in second..getTime(): number
- return time spent to this test in milliseconds.
Suitable for make performance tests of different versions of code and compaite results.
.add(func: Function, caseName?: string)
— add new benchmark unit to suite with given tested code and name (or generated). Throws DuplicateCaseNameException..execute(fixtures: any[] = []): ResultSet
— run all added benchmarks and return set of results.
Collection of Result
instances for every Bench in Suite.
.getFastest(): Result
- return the fastest bench result..getSlowest(): Result
- return the slowest bench result.
Super type of all throwed in library errors BaseException
.
Exported exceptions:
DuplicateCaseNameException
- throws on duplicate case name in Suite.add().
TSxUnit uses.
# only tests
npm test
# tests with coverage computing
npm run coverage