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
v29: from v28, removed reverse, micro-optimized Simpler Halved test, copy+paste array (now doubled)
</script>
<script src="//cdn.jsdelivr.net/lodash/2.4.1/lodash.min.js">
</script>
<script>
var lodash = _.noConflict();
</script>
var r, lodash = window.lodash;
function contains(array, value) {
var index = -1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return true;
}
}
return false;
}
function contains2(array, value) {
for (var i = 0, m = array.length; i < m; i++) {
if (array[i] === value) {
return true;
}
}
return false;
}
function contains3(array, value) {
for (var i = 0, l = array.length - 1, m=Math.floor(l/2); i <= m; i++) {
if (array[i] === value) return true;
else if (array[(l-i)] === value) return true;
}
return false;
}
function contains4(array, value) {
var l = array.length - 1;
var n = l*0.5;
var m = n>0?~~n:n==~~n?n:~~n-1; //math.floor()
for (var i = 0; i <= m; i++) {
if (array[i] === value) return true;
else if (array[(l-i)] === value) return true;
}
return false;
}
var array = [321, 182, 976, 413, 382, 697, 996, 629, 233, 412, 211, 424,
609,
965, 925, 560, 386, 807, 140, 952, 904, 833, 586, 139, 466, 226, 687, 119, 363, 784, 24, 792, 352, 376, 375, 606, 508, 716, 114, 291, 237, 544, 891, 518, 440, 395, 449, 841, 699, 284, 936, 818, 840, 162, 93];
Ready to run.
Test | Ops/sec | |
---|---|---|
Simple Loop |
| ready |
Simpler Loop |
| ready |
Simpler halved |
| ready |
Simpler Halved3 |
| ready |
lodash.indexOf |
| ready |
lodash.contains |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.