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
Testing the speed of iterating various sized arrays with straight for-loop or with a for-in-loop over its keys.
<script>
var _len = 1000000;
var _aut = new Array(_len);
for (var _i = 0; _i < _len; _i++) {
_aut[_i] = {value:_i};
}
function _genFilterFn(itemName, condition) {
var _iteratorName = '_i';
var _inputArrayLenName = '_len';
var _outputArrayName = '_result';
var _fnBody =
'\tvar ' + _iteratorName + ' = 0,\n\t\t' + _inputArrayLenName + ' = this.length,\n\t\t' + _outputArrayName + ' = [],\n\t\t' + itemName + ',_k=0;\n\n' +
'\twhile (' + _iteratorName + '++ < ' + _inputArrayLenName + ') {\n' +
'\t\t' + itemName + ' = this[' + _iteratorName + '];\n\n' +
'\t\tif (' + condition + ') {\n' +
'\t\t\t' + _outputArrayName + '[_k++] = ' + itemName + ';\n' +
'\t\t}\n' +
'\t}\n\n' +
'\treturn ' + _outputArrayName + ';';
return new Function(_fnBody);
}
var _nativeFilterFn = function _filter(item) {
return !!(item.value & 1);
};
var _generatedFilterFn = _genFilterFn('item', '!!(item.value & 1)');
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
native |
| ready |
generated |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.