Whatever

JavaScript performance comparison

Test case created by illumitata

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var input_len = 18;
  var weights1_len = 18 * 4;
  var hidden_len = 4;
  var bias1_len = hidden_len;
  
  var input = [];
  var weights1 = [];
  var bias1 = [];
  var hidden = [];
  
  var i, j;
  
  for(i = 0; i < input_len; i++) {
      input.push(Math.random());
  }
  
  for(i = 0; i < weights1_len; i++) {
      weights1.push(Math.random());
  }
  
  for(i = 0; i < bias1_len; i++) {
      bias1.push(Math.random());
  }
  
  for(i = 0; i < hidden_len; i++) {
      hidden.push(0);
  }
  
  var dot;
  var offset;

};
</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
one
for (i = 0; i < hidden_len; i++) {
    for (j = 0; j < input_len; j++) {
        hidden[i] += input[j] * weights1[i * input_len + j];
    }

    hidden[i] = hidden[i] + bias1[i];
    hidden[i] = 1 / (1 + Math.pow(Math.E, -hidden[i]));
}
pending…
two
for (var k = 0; k < input_len; k++) {
        hidden[0] += input[k] * weights1[0 * input_len + k];
        hidden[1] += input[k] * weights1[1 * input_len + k];
        hidden[2] += input[k] * weights1[2 * input_len + k];
        hidden[3] += input[k] * weights1[3 * input_len + k];
        hidden[4] += input[k] * weights1[4 * input_len + k];
    }

    hidden[0] = 1 / (1 + Math.pow(Math.E, -hidden[0] + bias1[0]));
    hidden[1] = 1 / (1 + Math.pow(Math.E, -hidden[1] + bias1[1]));
    hidden[2] = 1 / (1 + Math.pow(Math.E, -hidden[2] + bias1[2]));
    hidden[3] = 1 / (1 + Math.pow(Math.E, -hidden[3] + bias1[3]));
    hidden[4] = 1 / (1 + Math.pow(Math.E, -hidden[4] + bias1[4]));
}
pending…
three
var dot1 = 0.0;
    var dot2 = 0.0;
    var dot3 = 0.0;
    var dot4 = 0.0;
//    var dot5 = 0.0;
//    var dot6 = 0.0;
//    var dot7 = 0.0;
//    var dot8 = 0.0;

    for (var k = 0; k < input_len; k++) {
        dot1 += input[k] * weights1[0 * input_len + k];
        dot2 += input[k] * weights1[1 * input_len + k];
        dot3 += input[k] * weights1[2 * input_len + k];
        dot4 += input[k] * weights1[3 * input_len + k];
//        dot5 += input[k] * weights1[4 * input_len + k];
//      dot6 += input[k] * weights1[5 * input_len + k];
//        dot7 += input[k] * weights1[6 * input_len + k];
//        dot8 += input[k] * weights1[7 * input_len + k];
    }

    hidden[0] = 1 / (1 + Math.pow(Math.E, -dot1 + bias1[0]));
    hidden[1] = 1 / (1 + Math.pow(Math.E, -dot2 + bias1[1]));
    hidden[2] = 1 / (1 + Math.pow(Math.E, -dot3 + bias1[2]));
    hidden[3] = 1 / (1 + Math.pow(Math.E, -dot4 + bias1[3]));
//    hidden[4] = 1 / (1 + Math.pow(Math.E, -dot5 + bias1[4]));
//    hidden[5] = 1 / (1 + Math.pow(Math.E, -dot6 + bias1[5]));
//    hidden[6] = 1 / (1 + Math.pow(Math.E, -dot7 + bias1[6]));
//    hidden[7] = 1 / (1 + Math.pow(Math.E, -dot8 + bias1[7]));
pending…
four
for (i = hidden_len - 1; i >= 0; i--) {
    
    dot = 0.0;

    for (j = input_len - 1, offset = i * input_len; j >= 0; ) {
        dot += input[j] * weights1[offset + j]; j--;
        dot += input[j] * weights1[offset + j]; j--;
        dot += input[j] * weights1[offset + j]; j--;
        dot += input[j] * weights1[offset + j]; j--;
    }

    hidden[i] = 1 / (1 + Math.pow(Math.E, -(dot + bias1[i])));
}
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