test vs indexOf fast

JavaScript performance comparison

Revision 3 of this test case created by Vyacheslav Egorov

Preparation code

<script>
var BLACKHOLE;
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var regex = /salam/;
  var string = '123salam123';
  
  var strings = [string, string];
  var i = 0;
  
  var result;

};

Benchmark.prototype.teardown = function() {
  BLACKHOLE = result;

};
</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
var RegEx test
result = regex.test(strings[i = (i + 1) & 1])
pending…
inline RegEx test
result = /salam/.test(strings[i = (i + 1) & 1]);
pending…
String indexOf (boolean)
result = strings[i = (i + 1) & 1].indexOf('salam') !== -1;
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