So, I have a bunch of code that I'm looking into doing a little perf testing for. Most of these can be handling a lot of data and iterating over them, so it can be quite intensive. As jsperf is still unavailable for the time being, I was wondering what the best approach and alternative to take is?
JSPerf is back, but interface was bugging me. So I made another UI to Benchmark.js where you can test & share. Checki it at: https://jsbench.me
Hi, there is also https://www.measurethat.net/ , it is using benchmark.js as testing engine
i always use alert where i estimate the problem may be in the code. i hope it helps...
In Node.js it's easy now.
console.time('perf-label')
bigData.map( (item) => { /* do some heavy lifting */ } )
console.timeEnd('perf-label') // perf-label: 25333.627ms
console.time() uses process.hrtime in the background now. hrtime is the Node.js version of browsers performance.now function.
You can also run nested measurements.
console.time('entire-thing')
bigData.map( (item) => {
console.time('each-item')
/* do some heavy lifting */
console.timeEnd('each-item') // each-item: 101.927ms // each-item: 99.102ms // ... ...
} )
console.timeEnd('entire-thing') // entire-thing: 27456.221ms
Add those measurements to your tests to stop worrying where to do the measurements. If your test framework expects a boolean value, return true will do or it expects an assertion assert(1,1) is just fine. I can't recommend mixing real tests with performance measurements because the assertion will hurt the performance values and mocking may trick you too.
Duc Ng
mstime is another useful module (very tiny) to measure performance - github.com/ngduc/mstime