string array compare ADE

Benchmark created by Mike Stults on


Description

what is the fastest way to compare a string to a subset of elements in a char array

Setup

var stream = "TEST CASE".split('');
    var testcase = "TEST CASE";
    var start = 0,
      end = stream.length;

Test runner

Ready to run.

Testing in
TestOps/sec
join and compare
var sub = [];
for (var i = start; i <= end; i++) sub.push(stream[i]);
return sub.join('') === testcase;
ready
Compare each
var tc = testcase.split('');

for (var i = start; i <= end; i++)
  if (tc[i] !== stream[i]) return false;
return true;
ready
while loop
var tc = testcase.split(''), cnt = end;
while(cnt--)
  if (tc[cnt] !== stream[cnt]) return false;
return true;
ready

Revisions

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

  • Revision 1: published by Mike Stults on