bmcgin inlsit

JavaScript performance comparison

Test case created by Brian McGinity

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  String.prototype.inList1 = function(list) {
    return (Array.apply(null, arguments).indexOf(this.toString()) != -1)
  }
  String.prototype.inList2 = function(list) {
    return (list.indexOf(this.toString()) != -1)
  }

};
</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
inlist 1 - string args
var t = 'aphpa'.inList1('alpha', 'beta', 'charlie', 'delta');
var t = 'beta'.inList1('alpha', 'beta', 'charlie', 'delta');
var t = 'charlie'.inList1('alpha', 'beta', 'charlie', 'delta');
var t = 'delta'.inList1('alpha', 'beta', 'charlie', 'delta');
var t = 'echo'.inList1('alpha', 'beta', 'charlie', 'delta');
pending…
inlist 2 - arrary arg
var t = 'aphpa'.inList2(['alpha', 'beta', 'charlie', 'delta']);
var t = 'beta'.inList2(['alpha', 'beta', 'charlie', 'delta']);
var t = 'charlie'.inList2(['alpha', 'beta', 'charlie', 'delta']);
var t = 'delta'.inList2(['alpha', 'beta', 'charlie', 'delta']);
var t = 'echo'.inList2(['alpha', 'beta', 'charlie', 'delta']);
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