spice vs match into chunks

JavaScript performance comparison

Test case created by Peter Galiba

Info

Optimal splitting a text into 2 character chunks.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    // Define a string with 1000 characters.
    var text = new Array(101).join("1234567890");
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

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

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment