test whether variable is a string

JavaScript performance comparison

Test case created by Jeremy Danyow

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var s1 = 'hello',
      s2 = new String('hello');

};
</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
toString
var toString1 = Object.prototype.toString.call(s1) === '[object String]',
    toString2 = Object.prototype.toString.call(s2) === '[object String]';
pending…
typeof || instanceof
var typeOfInstanceOf1 = typeof s1 === 'string' || s1 instanceof String,
    typeOfInstanceOf2 = typeof s2 === 'string' || s2 instanceof String;
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