Longest string in array

Benchmark created by maga on


Preparation HTML

<script>
  a = ['adf', 'asdfdf', 'asdfdf', 'aasdfdf', 'addddddf', 'asdfdf', 'assdf', 'adfd']
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Straight
function Ls(a) {
 var l = 0;
 for (var i = 0; i < a.length; i++) {
  if (a[l].length < a[i].length) {
   l = i;
  }
 }
 return l;
}
ready
Optimized
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 li;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.