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
Lets compare classic memoization to the new harmony proxies.
<script>
// from JavaScript: The Good Parts
// by D. Crockford
function memoizer(memo, fundamental) {
var shell = function(n) {
var result = memo[n];
if (typeof result !== 'number') {
result = fundamental(shell, n);
memo[n] = result;
}
return result;
};
return shell;
}
function proxyMemo(start, fn) {
var cache = Object.create(Proxy.create({
getPropertyDescriptor: function(name) {
var index = ~~name;
if (index == name) {
return {
get: function() {
var val = fn.call(this, index);
Object.defineProperty(this, index, {
value: val,
enumerable: true,
writable: true,
configurable: true
});
return val;
}
};
} else {
return Object.getOwnPropertyDescriptor(Object.prototype, name);
}
},
getOwnPropertyDescriptor: function(name) {
return this.getPropertyDescriptor(name);
},
getPropertyNames: function() {
return [];
},
getOwnPropertyNames: function() {
return [];
},
delete: function() {
return false;
},
fix: function() {
return;
}
})),
prop;
for (prop in start) {
Object.defineProperty(cache, prop, {
value: start[prop],
enumerable: true
})
}
return cache;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Classic |
| ready |
Proxy |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.