tldr; Introducing Exacta π - lightweight, zero-dependencies benchmarking utility you can run as part of your test suite.
Motivation
Whether you are playing with challenges on Codewars or LeetCode, or just need to compare which method of finding duplicates in array for your project is faster, eventually you need to benchmark performance of your code.
Libraries like Benchmark.js do really good job and I do not mean to compete with full-blown benchmarking suite. I was, however, looking for something simpler and lighter where I'd have more control and be able to run it as part of unit tests.
Solution
Here comes Exacta - lightweight, zero-dependencies benchmarking utility you can run as part of your test suite.
https://github.com/kraiovsky/exacta
Here's an example:
const Race = require('exacta')
const fn1 = require('./fn1')
const fn2 = require('./fn2')
const param1 = [1, 2, 3]
const param2 = 'your string'
test(`benchmark`, () => {
new Race()
.setRuns(100000) // optional, defaults to 1000
.addFn(fn1) // add functions to run...
.addFn(fn2) // ...as many as you have, one at a time
.setParams(param1, param2) // add parameters that functions take
.run() // and finally let them run
})
it will output something like this:
--= Race results =--
# of runs: 100000
Parameters: [[1,2,3],"your string"]
Function Run time [β]
====================================
π fn1() 10 ms
------------------------------------
fn2() 20 ms
------------------------------------
Why Exacta?
Exacta stands for a method of betting, as on a horserace, in which the bettor must correctly pick those finishing in the first and second places in precisely that sequence.
Top comments (0)