dec vs imp (v3)

Revision 3 of this benchmark created by sem karaman on


Description

declarative js vs imperative js

Test runner

Ready to run.

Testing in
TestOps/sec
declarative
function sumOfSquares(nums) {
  return nums
    .map(function(num) {
      return num * num;
    })
    .reduce(function(start, num) {
      return start + num;
    }, 0);
}

console.log(sumOfSquares([1, 2, 3, 4, 5]));
ready
imperative
function sumOfSquares(nums) {
  var i, sum = 0,
    squares = [];
  for (i = 0; i < nums.length; i++) {
    squares.push(nums[i] * nums[i]);
  }

  for (i = 0; i < squares.length; i++) {
    sum += squares[i];
  }

  return sum;
}

console.log(sumOfSquares([1, 2, 3, 4, 5]));
ready

Revisions

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

  • Revision 3: published by sem karaman on