greater than or not equal

JavaScript performance comparison

Test case created by magikMaker


Test to find out whether it's faster to test against '!= -1' or against '>= 0' when using indexOf on a String.

Preparation code

Benchmark.prototype.setup = function() {
    var search = 'find the cat',
        string = 'How fast can we find the cat';

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
equals -1
var test = string.indexOf(search) != -1
greater than
var test = string.indexOf(search) >= 0

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

Compare results of other browsers


Add a comment