jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
I don't like flat function pattern:
function calculateSquare(width, height, x, y, validate, typeCheck) { /* function body */ }
because usage of such function is not clear:
calculateSquare(100, 50, 10, 15, true, false);
When you see on such calling hard to say what is true and false here. But this exmaple looking much better:
calculateSquare({ width : 100, height : 50, x : 10 y : 15, validate : true, typeCheck : false });
Related article: https://gcanti.github.io/2014/09/25/six-reasons-to-define-constructors-with-only-one-argument.html
But what about performance?
Be careful also second test is available: http://jsperf.com/hash-vs-flat-function-arguments-2
// flat patter
function flat_sum(first, second, third) {
return first + second + third;
}
// hash patter
function hash_sum(params) {
return params.first + params.second + params.third;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Flat sum |
| ready |
Hash sum |
| ready |
cached hash |
| ready |
cached hash 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.