substring vs match 2

JavaScript performance comparison

Test case created by mdomba

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var str1 = "columnId",
      str2 = "columnId[]";

};
</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
substring, not found
t1 = (str1.substring(str1.length - 2) === '[]') ? str1 : str1+'[]';
pending…
match, not found
t1 = (str1.match(/.+\[\]$/)) ? str1 : str1+'[]';
pending…
substring, found
t2 = (str2.substring(str2.length - 2) === '[]') ? str2 : str2+'[]';
pending…
match, found
t2 = (str2.match(/.+\[\]$/)) ? str2 : str2+'[]';
pending…

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

Compare results of other browsers

0 Comments