mean comparison

JavaScript performance comparison

Test case created by aelliott1485

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const mean = (numbers) => {
    let total = 0,
      i;
    for (i = 0; i < numbers.length; i += 1) {
      total += numbers[i];
    }
    return total / numbers.length;
  };
  
  const mean2 = (numbers) => {
    let total = 0;
    
    for (const num of numbers) {
      total += num;
    }
    return total / numbers.length;
  };
  const sum = (a, b) => a + b
  const meanReduction = numbers => {
    return numbers.reduce(sum, 0) / numbers.length;
  }
  const nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

};
</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
original
mean(nums);
pending…
for...of
mean2(nums);
pending…
reduction
meanReduction(nums);
pending…

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

0 Comments