string compare vs index

Benchmark created by Alex on


Setup

var s1 = "some string";
    var s2 = "some other string";
    var s = "current string";
    
    var sArr = [s1, s2];
    var index = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
String compare
if(s === s1) {
  s = s2;
} else {
  s = s1;
}
ready
Index
s = sArr[++index % 2]
ready

Revisions

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