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
<script>
</script>
/**
* Compile iterator function for a specific type.
*/
var compileIterator = function(typeProperties) {
// pre-compile constant iteration over object properties
var iteratorFunStr = '(function(obj, cb) {\n';
for (var i = 0; i < typeProperties.length; ++i) {
iteratorFunStr += 'cb(obj.' + typeProperties[i] + ');\n';
};
iteratorFunStr += '})';
// actually compile and return the function
return eval(iteratorFunStr);
};
// now, we can build custom type descriptions of varying sizes
var NObjectSize = 30000;
// create a custom test "type property set"
var testTypeProperties = [];
for (var i = 1; i <= NObjectSize; ++i) {
testTypeProperties.push('a' + i); // non-numeric properties to be on the safe side
};
// compile iterator function
var iteratorFun = compileIterator(testTypeProperties);
// create a test object
var createTestObject = function() {
var objString = '({'
for (var i = 0; i < testTypeProperties.length; ++i) {
objString += testTypeProperties[i] + ': ' + (i + 1) + ',\n';
}
objString += '});';
return eval(objString);
};
var o1 = createTestObject();
var o2 = createTestObject();
var aFunction = function(total, next) {
return total * next + 1;
};
Ready to run.
Test | Ops/sec | |
---|---|---|
for ... in (sum) |
| ready |
Pre-compiled iterator (sum) |
| ready |
for ... in (copy) |
| ready |
Pre-compiled iterator (copy) |
| ready |
for ... in (function call) |
| ready |
Pre-compiled iterator (function call) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.