Object.toString vs Number.toString

JavaScript performance comparison

Test case created by Marc

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var numArray = [1, 2, 3, 4, 5, 6];
  var strArray = ['a', 'b', 'c', 'd', 'e', 'f'];
  var objArray = [{a:'a'}, {b:'b'}, {c:'c'}, {d:'d'}, {e:'e'}, {f:'f'}];

};
</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
Number
var res = ''
for(var i = 0; i < numArray.length; i++){
  res = res + numArray[i].toString();
}
pending…
String
var res = ''
for(var i = 0; i < strArray.length; i++){
  res = res + strArray[i].toString();
}
pending…
Object
var res = ''
for(var i = 0; i < objArray.length; i++){
  res = res + objArray[i].toString();
}
pending…

Compare results of other browsers

Revisions

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

0 Comments