type-inference-performance

JavaScript performance comparison

Revision 7 of this test case created by Igor Santos

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array_of_ints = [0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    var array_of_mixed = [0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, undefined];
    var array_of_int_strings = ['0.5', '1', '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9',  '10'];
   
    function sum_of_ints() {
      var sum = 0;
      for (var i = 0; i < array_of_ints.length; i++) {
        sum += array_of_ints[i];
      }
    }
   
    function sum_of_mixed() {
      var sum = 0;
      for (var i = 0; i < array_of_mixed.length; i++) {
        sum += array_of_mixed[i];
      }
    }
   
    function sum_of_strings() {
      var sum = 0;
      for (var i = 0; i < array_of_mixed.length; i++) {
        sum += parseFloat(array_of_int_strings[i]);
      }
    }
   
    function sum_of_parsed_strings() {
      var sum = 0;
      var ints = [];
      for (var i = 0; i < array_of_mixed.length; i++) {
        ints[i] = parseFloat(array_of_int_strings[i]);
      }
      for (var i = 0; i < array_of_mixed.length; i++) {
        sum += ints[i];
      }
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
array of ints
sum_of_ints();
pending…
array of mixed
sum_of_mixed();
pending…
array of integer strings
sum_of_strings();
pending…
array of parsed strings
sum_of_parsed_strings();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment