perfalize
A simple way to analyze performance in JavaScript programs.
USAGE
Install with npm
npm install perfalize
Use it in your program:
import { perfalize, enable } from 'perfalize'
if (process.env.PROFILE === '1') {
enable()
enable({
minimum: 1,
})
}
const thingDone = perfalize('do thing')
doSomething()
thingDone()
const done = perfalize('some promise action')
const promise = someAsyncFunction(args)
done(promise)
function someFunction() {
const done = perfalize('someFunction')
doSomething()
doSomethingElse()
return done(doSomeSlowThing())
}
import { perfalizeFn } from 'perfalize'
const someFunction = perfalizeFn('someFunction', () => {
doSomething()
doSomethingElse()
return doSomeSlowThing()
})
What is Collected
The goal of any performance analysis tool should be to have as
little impact on the system under test as possible. So, not very
much is tracked, and it just does a bit of basic arithmetic on
each sample collected.
Perfalize tracks:
- number of calls (ie, the number of times that the sample name
was triggered)
- total time spent
- mean time per sample
Why not just use node --prof?
In many cases, you definitely should! I'm a huge fan. This is
somewhat of a different thing.
node --perf tracks everything in your program, all C++ and
JS. That's ideal for coverage, and can be very useful when
you're not sure if the bottleneck is even in your code. It also
provides a "bottoms up" view that is hard to do correctly with
manual perf sampling.
But, that can also be noisy, and sometimes overkill if you just
want a simple debugging tool that you can turn on with an
enviroment variable.