README
brisky-performance
Simple performance benchmarking tools (browser and node)
Precise time measurement
uses hrTime
, webkit.performance
or Date.now
const { time } = require('brisky-performance')
const start = time() // array in node, ms in browser
const elapsed = time(start)
When called without arguments, returns a time object When called with an argument, returns the difference between the current time and the time passed in as argument, in milliseconds
Comparing functions
Compare a function vs another, usefull for writing perf tests
const perf = require('brisky-performance')
// The following test will pass if `subject` executes at least 2 times as fast as `reference`
perf(function subject () {}, function reference () {}, 2)
perf(() => {}, () => {}, 'some test')
perf (subject, reference, *margin, *loop, *label)
subject
- function to measurereference
- function to compare withsubject
margin
- number of times fastersubject
must be compared toreference
for the test to passloop
- Number of times to run the functions (default:10
)label
- Override label
When passing a string to margin or loop it will become the label
Finding IC inconsistencies
Helps finding type mismatches in functions, just counts them. Usefull when you see the v8 warning "optmized too many times" It's usualy too many type differences passed into the arguments
const { type } = require('brisky-performance')
function someFunction (a, b) {
type.test(someFunction, a, b)
}
someFunction('hello', 1)
someFunction([ 1, 2 ], null)
type.someFunction // →
// {
// a: { string: 1, array: 1 },
// b: { number: 1, null: 1 }
// }
type.test('customkey', someFunction, 1, 2)
type.customkey // → { a: { number: 1 }, b: { number: 1 } }
Uses tape internally, which produces TAP (Test Anything Protocol) output.