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>
var CACHE_1 = {};
var CACHE_2 = {};
//var CACHE_3 = {};
var CACHE_4 = {};
function T1(name, _cache){ this.name = name; this.cache = _cache; }
T1.prototype.getCache = function(i) { return this.cache[i] };
T1.prototype.setCache = function(i, val) { return this.cache[i] = val };
function T5(name){ this.name = name; }
T5.prototype.getCache = function(i) { return this[i] };
T5.prototype.setCache = function(i, val) { return this[i] = val };
function T6(name){
this.name = name;
this.getCache = function(i) { return this[i]; };
this.setCache = function(i, val) { return this[i] = val; };
}
function T7(name){ this.name = name; }
T7.prototype.ptype = T7.prototype;
T7.prototype.getCache = function(i) { return this.ptype[i] };
T7.prototype.setCache = function(i, val) { return this.ptype[i] = val };
function C1(name) {
this.name = name;
this.keys = new Array(100);
this.vals = new Array(100);
this.len = 0;
};
C1.prototype.getCache = function(key) {
var _this = this;
var i, len = _this.len;
for(i=0;i!==len;i+=1) if(_this.keys[i]===key) return _this.vals[i];
return false;
};
C1.prototype.setCache = function(key, val) {
var _this = this;
var i, len = _this.len, found = false;
for(i=0;i!==len;i+=1) if(_this.keys[i]===key) {
found = true;
break;
}
if(!found) {
_this.len+=1;
_this.keys[i] = key;
}
_this.vals[i] = val;
return true;
};
function C2(name, _cache) {
this.name = name;
this.cache = _cache;
this.len = 0;
}
C2.prototype.getCache = function(key) {
var i, cache = this.cache;
for(i=0;i!==this.len;i+=1) { if(cache[i][0]===key) return cache[i][1]; }
return false;
};
C2.prototype.setCache = function(key, val) {
var _this = this;
var i, len = _this.len, found = false;
for(i=0;i!==len;i+=1) if(_this.cache[i][0]===key) {
found = true;
break;
}
_this.cache[i] = [key, val];
if(!found) _this.len+=1;
return true;
};
function C3(name) {
this.name = name;
this.keys = new Array(100);
this.vals = new Array(100);
this.len = 0;
};
C3.prototype.getCache = function(key) {
var _this = this;
if(_this.len) return _this.vals[_this.keys.indexOf(key)];
return false;
};
C3.prototype.setCache = function(key, val) {
var _this = this;
var i, len = _this.len, found = false;
for(i=0;i!==len;i+=1) if(_this.keys[i]===key) {
found = true;
break;
}
if(!found) {
_this.len+=1;
_this.keys[i] = key;
}
_this.vals[i] = val;
return false;
};
function T2(name, _cache) {
this.name = name;
this.cache = _cache;
this.getCache = function(i) {
return this.cache[i];
};
this.setCache = function(i, val) {
this.cache[i] = val;
return false;
};
//return this;
};
var t3 = {
cache : {},
getCache : function(i) {
return this.cache[i];
},
setCache : function(i, val) {
this.cache[i] = val;
return false;
}
};
var t4 = (function(_cache) {
var getCache = function(i) {
return this.cache[i];
};
var setCache = function(i, val) {
this.cache[i] = val;
};
return {
cache :_cache,
getCache : getCache,
setCache : setCache
};
}(CACHE_4));
var t1 = new T1('T1', CACHE_1);
var t2 = new T2('T2', CACHE_2);
//var t3 = T3(CACHE_3);
//var t4 = T4(CACHE_4);
var c1 = new C1('C1');
//var c2 = new C2('C2', CACHE_5);
var c3 = new C3('C3');
var t5 = new T5('T5');
var t6 = new T6('T6');
var t7 = new T7('T7');
//function setHelper(c, k, v){ c[k]=v };
//function getHelper(c, k){ return c[k] };
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Prototype |
| ready |
Property (this) |
| ready |
Module |
| ready |
Prototype + Emulated Assoziative Key Access via 2 seperate Arrays |
| ready |
Prototype + Emulated Assoziative Key Access via 2 seperate Arrays + indexOf |
| ready |
Property Storage + Prototype Get/Set |
| ready |
Property Storage + Property Get/Set |
| ready |
Prototype Storage + Prototype Get/Set |
| ready |
Object Literal Notation |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.