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:
Compare native Map implementation vs using an object as a hash map.
Preparation HTML
<script>functionrandomString()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
</script>
Setup
var map = newMap();
var obj = {};
var keycache = [];
var valcache = [];
var map2 = newMap();
var map3 = newMap();
var map4 = newMap();
var map5 = newMap();
var obj2 = {};
for (var i=0; i < 1000; i++) {
var key = randomString();
var val = randomString();
map2.set(key,val);
map3.set(key,val);
map4.set(key,val);
map5.set(key,val);
obj2[key] = val;
keycache[i] = key;
valcache[i] = val;
}
Test runner
Ready to run.
Testing in
Test
Ops/sec
map.set(key,val)
for (var i=0; i < 1000; i++) {
var key = keycache[i];
var val = valcache[i];
map.set(key,val);
}
ready
obj[key] = val;
for (var i=0; i < 1000; i++) {
var key = keycache[i];
var val = valcache[i];
obj[key] = val;
}
ready
Many Obj Creation
var objs = [],
obj;
for (var i=0; i < 1000; i++) {
obj = {};
var key = keycache[i];
var val = valcache[i];
for (var j=0; j < 5; j++) {
obj[key] = val;
}
}
ready
Many Map Creation
var objs = [],
obj;
for (var i=0; i < 1000; i++) {
obj = newMap();
var key = keycache[i];
var val = valcache[i];
for (var j=0; j < 5; j++) {
obj.set(key,val);
}
}