perf-lane
v1.0.7
Published
Performance testing harness for node
Downloads
11
Readme
perf-lane
Performance testing harness for Node.js
This library exists to:
- ease benchmarking with confidence, help write repeatable tests with stable results
- simplify comparing performance of alternate solutions and for different data sizes
- simplify testing different setups
Examples
const test = require('perf-lane')
const assert = require('assert')
test.for_n([
[1, 1],
[10, 55],
[30, 832040],
[40, 102334155]
])
test('fibonacci_1', (p) => {
function fibonacci_1(n) {
return n < 1 ? 0
: n <= 2 ? 1
: fibonacci_1(n - 1) + fibonacci_1(n - 2)
}
let actual = fibonacci_1(p.n)
assert.equal(actual, p.expected, `fibonacci(${p.n})`)
})
test('fibonacci_2', (p) => {
const cache = [0, 1, 1]
function fibonacci_2(n) {
cache[n] = cache[n] || fibonacci_2(n - 1) + fibonacci_2(n - 2)
return cache[n]
}
let actual = fibonacci_2(p.n)
assert.equal(actual, p.expected, `fibonacci(${p.n})`)
})
$ perf-lane fibonacci.perf.js
'fibonacci fibonacci_1' for n=1 takes 0-1ms p(95)=0ms tps=6521739 (150000 runs)
'fibonacci fibonacci_1' for n=10 takes 0-1ms p(95)=0ms tps=852273 (150000 runs)
'fibonacci fibonacci_1' for n=30 takes 15-22ms p(95)=15ms tps=65 (978 runs)
'fibonacci fibonacci_1' for n=40 takes 1864-1951ms p(95)=1864ms tps=1 (30 runs)
'fibonacci fibonacci_2' for n=1 takes 0-1ms p(95)=0ms tps=3061224 (150000 runs)
'fibonacci fibonacci_2' for n=10 takes 0-1ms p(95)=0ms tps=688073 (150000 runs)
'fibonacci fibonacci_2' for n=30 takes 0-2ms p(95)=0ms tps=327511 (150000 runs)
'fibonacci fibonacci_2' for n=40 takes 0-1ms p(95)=0ms tps=274725 (150000 runs)
Documentation
test(title: string, fn: (p) => {})
- declare test function with given title.
Test is either sync or returns Promise.
p
Attributes:
p.n
- currentn
of declaredfor_n
p.expected
- currentexpected
of declaredfor_n
p.i
- test invokation counter, starts from 0 for eachn
p.name
- test file namep.test
- test titlep.before(fn)
- preparation section, not counted in test time
test.async(title: string, fn: (p) => {})
- declare async test function, that terminates by calling end
callback.
p
Attributes: see test(title, fn)
, additionally:
p.start
- callback to be called on test start (optional)p.end
- callback to be called on test end (required)
test.for_n(array)
- declare list of [n, expected]
pairs for which test will be invoked.
Use it to test performance for different problem sizes,
use expected
in assertions to make sure tested code is
not only fast but also correct.
test.beforeEach(fn)
- declare function to be called before each test function invocation
test.afterEach(fn)
- declare function to be called after each test function invocation
test.before(fn)
- declare function to be called before invoking any tests in a test file
test.after(fn)
- declare function to be called after invoking all tests in a test file
test.run()
- runs tests, equivalent to running perf-lane
from command line.
test.loggers
- list of default available loggers
test.options
- Available options
transactionsPerTest
- number of transactions per test, to properly calculate TPSminSecs
- minimum time period to repeat single testmaxSecs
- maximum time period to repeat single testminRuns
- minimum numer of single test invocationsmaxRuns
- maximum number of single test invocationslogger
- logger functionreport
- report generator functionformat
- report charts,svg
orpng
outFile
- report log output fileenvName
- environment name, defaults toprocess.env.HOSTNAME
orprocess.env.TEST_ENV