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>
CACHE_1 = {};
CACHE_2 = {};
CACHE_3 = {};
CACHE_4 = {};
CACHE_5 = new Array(100);
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) { this.cache[i] = val; return false; };
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 = function (_cache) {
return {
cache : _cache,
getCache : function(i) {
return this.cache[i];
},
setCache : function(i, val) {
this.cache[i] = val;
return false;
}
};
};
var T4 = function (_cache) {
var $cache = _cache;
return {
cache : $cache,
getCache : function(i) {
return this.cache[i];
},
setCache : function(i, val) {
this.cache[i] = val;
return false;
}
};
};
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');
</script>
//no definitions here!!!
Ready to run.
Test | Ops/sec | |
---|---|---|
Set Using prototype |
| ready |
Set Using this |
| ready |
Set Using Module |
| ready |
Set Using Module 2 |
| ready |
Set Using prototype + Emulated Assoziative Key Access with 2 seperate Arrays |
| ready |
Set Using prototype + Emulated Assoziative Key Access with an 2D-Array |
| ready |
Set Using prototype + Emulated Assoziative Key Access with 2 seperate Arrays + indexOf |
| ready |
Get Using prototype |
| ready |
Get Using this |
| ready |
Get Using Module |
| ready |
Get Using Module 2 |
| ready |
Get Using prototype + Emulated Assoziative Key Access with 2 seperate Arrays |
| ready |
Get Using prototype + Emulated Assoziative Key Access with an 2D-Array |
| ready |
Get Using prototype + Emulated Assoziative Key Access with 2 seperate Arrays + indexOf |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.