Array get range VS Array contains

JavaScript performance comparison

Test case created by Altanmur


this example is search from array.

  1. if in for always check
  2. finding start,end index. no if for start between end index.

data is sorted; iteration number is same;

Preparation code

Benchmark.prototype.setup = function() {
    var filtered = [];
    var data = ["а",
    "аар саар",
    "адал явдал",

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
if StartsWith in For
var search = 'ав';
var flag = false;
for(var i = 26; i < data.length; i++){
 if(data[i].indexOf(search) == 0){
   flag = true;
 }else if(flag == true && filtered.length != 0){
no if in for, before detecting start, end index
var startIndex = 26;
var endIndex = 83;

for(var i = startIndex; i <= endIndex; i++){

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment