1.4.2 • Published 7 years ago

brisky-performance v1.4.2

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

#brisky-performance Simple performance benchmarking tools (browser and node)

Build Status js-standard-style npm version Coverage Status


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 measure
  • reference - function to compare with subject
  • margin - number of times faster subject must be compared to reference for the test to pass
  • loop - 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.

1.4.2

7 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago