indexOf vs bitwise not comparison (v3)

Revision 3 of this benchmark created on


Description

In trying to find if a string contains a substring, is it faster to use a logical comparison or bitwise operations to create a logical result.

http://dreaminginjavascript.wordpress.com/2008/07/04/28/

Note: this test will most likely cause Interget Explorer to display a script timeout message so adjust your registry settings accordingly.

Setup

var alphabet = "abcdefghijklmnopqrstuvwxyz";
    var index = alphabet.indexOf("l");
    var noindex = alphabet.indexOf("1");

Test runner

Ready to run.

Testing in
TestOps/sec
Logical Greater Than
index > -1
ready
Bitwise NOT
!~index
ready
Logical Not Equals
index != -1
ready
Logical Strict Not Equals
index !== -1
ready
Add One
index + 1
ready
Logical Greater Than (Not Found)
noindex > -1
ready
Bitwise NOT (Not Found)
!~noindex
ready
Logical Not Equals (Not Found)
noindex != -1
ready
Logical Strict Not Equals (Not Found)
noindex !== -1
ready
Add One (Not Found)
noindex + 1
ready

Revisions

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