spice vs match into chunks

Benchmark created by Peter Galiba on


Description

Optimal splitting a text into 2 character chunks.

Setup

// Define a string with 1000 characters.
    var text = new Array(101).join("1234567890");

Test runner

Ready to run.

Testing in
TestOps/sec
slice
var s = text,
    l = s.length,
    lc = 0,
    out = [],
    c = 0;
for (; lc < l; c++) {
  out[c] = s.slice(lc, lc +=2);
}
ready
match
var s = text,
    out = s.match(/.{1,2}/g);
ready

Revisions

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