开发者

Why searching for the middle item in an array of 100 is faster than in an array of 10 items? [closed]

It's diffi开发者_运维知识库cult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I made some tests to check this but is quite not expected: http://jsperf.com/value-in-array-or-object

You can run those tests too..


It's not faster. It appeared faster in your tests because you were assigning rather than comparing in the tests for 50 and 100 items:

if(a100[x] = 'item50'){
    break;
}

The test with 10 items was correct:

if(a10[x] === 'item5'){
    break;
}

See updated test cases here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜