Identifying Hexadecimal Strings

JavaScript performance comparison

Test case created by Suraj Patel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var hexString = "0x12345";
  var nonHexString = "12345";
  var longHexString = "-0X123456789123456789";
  var longNonHexString = "123456789123456789";
  
  function charAt(str) {
    if (str.charAt(1).toLowerCase() === "x" || str.charAt(2).toLowerCase() === "x") {
      return true;
    };
  };
  
  function charAtTwo(str) {
    if (str.charAt(1) === "x" || str.charAt(2) === "x" || str.charAt(1) === "X" || str.charAt(2) === "X") {
      return true;
    };
  };
  
  function regExp(str) {
    if (/x/i.test(str)) {
      return true;
    };
  };
  
  function indexOf(str) {
    if (str.toLowerCase().indexOf("x") > -1) {
      return true;
    };
  };
  
  function indexOfTwo(str) {
    if (str.indexOf("x") > -1 || str.indexOf("X") > -1) {
      return true;
    };
  };

};
</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
charAt
charAt(hexString);
charAt(longHexString);
charAt(nonHexString);
charAt(longNonHexString);
charAt(nonHexString);
charAt(longNonHexString);
charAt(nonHexString);
charAt(longNonHexString);
pending…
charAtTwo
charAtTwo(hexString);
charAtTwo(longHexString);
charAtTwo(nonHexString);
charAtTwo(longNonHexString);
charAtTwo(nonHexString);
charAtTwo(longNonHexString);
charAtTwo(nonHexString);
charAtTwo(longNonHexString);
pending…
indexOf
indexOf(hexString);
indexOf(longHexString);
indexOf(nonHexString);
indexOf(longNonHexString);
indexOf(nonHexString);
indexOf(longNonHexString);
indexOf(nonHexString);
indexOf(longNonHexString);
pending…
indexOfTwo
indexOfTwo(hexString);
indexOfTwo(longHexString);
indexOfTwo(nonHexString);
indexOfTwo(longNonHexString);
indexOfTwo(nonHexString);
indexOfTwo(longNonHexString);
indexOfTwo(nonHexString);
indexOfTwo(longNonHexString);
pending…
regExp
regExp(hexString);
regExp(longHexString);
regExp(nonHexString);
regExp(longNonHexString);
regExp(nonHexString);
regExp(longNonHexString);
regExp(nonHexString);
regExp(longNonHexString);
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