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 arr = ['adf', 'asdfdf', 'asdfdf', 'aasdfdf', 'addddddf', 'asdfdf', 'assdf', 'adfd'];
function Ls(a) {
var l = 0;
for (var i = 0; i < a.length; i++) {
if (a[l].length < a[i].length) l = i;
}
return a[l];
}
function Lo(a) {
var li = 0,
ll = a[0].length !== 0 ? a[0].length - 1 : 0;
for (var i = 0; i < a.length; i++) {
if (a[i][ll]) {
ll = a[i].length - 1;
li = i;
}
}
return a[li];
}
function Ls2(a) {
var l = a.length - 1;
var i = l;
if (i) while (i--) if (a[l].length < a[i].length) l = i;
return a[l];
}
function timo_longest(a) {
var c = 0,
d = 0,
l = 0,
i = a.length;
if (i) while (i--) {
d = a[i].length;
if (d > c) {
l = i;
c = d;
}
}
return a[l];
}
var Sort = function(arr)
{
return arr.sort(function(a, b) {
return b.length - a.length;
})[0];
};
var Reduce = function(arr)
{
return arr.reduce(function(a, b) {
return a.length > b.length ? a : b;
});
}
function longestStr(a) {
var i=a.length - 1,m=0,j=0;
for(i; i >= 0; i--) {
if(a[i].length > m){
m=a[i].length;
j=i;
}
}return a[j];
}
function longestLength(a) {
var i=a.length - 1,m=0,j=0;
for(i; i >= 0; i--) {
m = Math.max(a[i].length, m);
}return m;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Straight |
| ready |
Optimized |
| ready |
Straight2 |
| ready |
timo_longest |
| ready |
Sort |
| ready |
Reduce |
| ready |
one less var,more .length references |
| ready |
Return length, not string |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.