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
function ifElseTest(stuff) {
if(stuff <= 3) {
if (stuff === 1) return "food";
if (stuff === 2) return "building";
return "furniture";
} else {
if (stuff === 4) return "driving";
if (stuff === 5) return "drink";
return "nothing";
}
};
function switchTest(stuff) {
switch (stuff) {
case 1:
return "food";
break;
case 2:
return "building";
break;
case 3:
return "furniture";
break;
case 4:
return "driving";
break;
case 5:
return "drink";
break;
case 6:
return "nothing";
break;
}
};
var lookupTable = {
1: function() {
return "food";
},
2: function() {
return "building";
},
3: function() {
return "furniture";
},
4: function() {
return "driving";
},
5: function() {
return "drink";
},
6: function() {
return "nothing";
}
};
var lookupArray = [
function() {
// do nothing
},
function() {
return "food";
},
function() {
return "building";
},
function() {
return "furniture";
},
function() {
return "driving";
},
function() {
return "drink";
},
function() {
return "nothing";
}
];
var lookupTableString = {
a: function() {
return "food";
},
b: function() {
return "building";
},
c: function() {
return "furniture";
},
d: function() {
return "driving";
},
e: function() {
return "drink";
},
f: function() {
return "nothing";
}
};
var lookupTableNumericString = {
'1': function() {
return "food";
},
'2': function() {
return "building";
},
'3': function() {
return "furniture";
},
'4': function() {
return "driving";
},
'5': function() {
return "drink";
},
'6': function() {
return "nothing";
}
};
Ready to run.
Test | Ops/sec | |
---|---|---|
if else |
| ready |
switch |
| ready |
lookup table - integer keys - string access |
| ready |
lookup array |
| ready |
lookup table - integer keys - integer access |
| ready |
lookup table - string keys |
| ready |
lookup table - numeric string keys - string access |
| ready |
lookup table - numeric string keys - integer access |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.