Get second part

JavaScript performance comparison

Test case created by chaimleib

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const wood = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?";
  const axe = "if";
  const deleteFirstRgx = RegExp('.*?' + axe);
  const rgx = RegExp(axe);

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
slice on indexOf
const result = wood.slice(wood.indexOf(axe) + axe.length);
pending…
substr on indexOf
const result = wood.substr(wood.indexOf(axe) + axe.length);
pending…
(only 2) split and index
const result = wood.split(axe)[1];
pending…
(only 2) split and deconstruct
const [_, result] = wood.split(axe);
pending…
(only 2) split and pop
const result = wood.split(axe).pop();
pending…
precompiled deletion regex
const result = wood.replace(deleteFirstRgx, '');
pending…
(only 2) split precompiled regex and deconstruct
const [_, result] = wood.split(rgx);
pending…
split, deconstruct, join
const [_, ...parts] = wood.split(axe);
const result = parts.join(axe);
pending…
split, slice, join
const result = wood.split(axe).slice(1).join(axe);
pending…
(only 2) split precompiled regex and index
const result = wood.split(rgx)[1];
pending…
(only 2) split precompiled regex and pop
const result = wood.split(rgx).pop();
pending…
split precompiled regex, slice and join
const result = wood.split(rgx).slice(1).join(axe);
pending…
constructed deletion regex
const result = wood.replace(RegExp('.*?' + axe), '');
pending…
split regex, slice and join
const result = wood.split(RegExp(axe)).slice(1).join(axe);
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.

0 Comments