reduce find longest

Benchmark created by Carlo on


Setup

var entries = [1, 8, 6, 5, 4, 9, 3, 1, 34, 77, 4, 22, 45, 65, 23, 98, 55, 12, 16, 3];

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0, longest = ''; i < entries.length; ++i) {
  if (entries[i].length > longest.length) longest = entries[i];
}
ready
reduce
entries.reduce(function(longest, entry) {
  return entry.length > longest.length ? entry : longest;
}, '');
ready

Revisions

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

  • Revision 1: published by Carlo on