Array Operations

JavaScript performance comparison

Test case created by asleepysamurai

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  tripExpenses10 = [];
  
  while(tripExpenses10.length < 10){
      tripExpenses10.push({
          amount: (Math.random() * (250) + 1),
          currency: ['INR', 'USD'][Math.round(Math.random() % 2)],
          paid: [false, true][Math.round(Math.random() % 2)]
      });
  }
  
  tripExpenses10000 = [];
  
  while(tripExpenses10000.length < 10000){
      tripExpenses10000.push({
          amount: (Math.random() * (250) + 1),
          currency: ['INR', 'USD'][Math.round(Math.random() % 2)],
          paid: [false, true][Math.round(Math.random() % 2)]
      });
  }
  
  tripExpenses100000 = [];
  
  while(tripExpenses100000.length < 100000){
      tripExpenses100000.push({
          amount: (Math.random() * (250) + 1),
          currency: ['INR', 'USD'][Math.round(Math.random() % 2)],
          paid: [false, true][Math.round(Math.random() % 2)]
      });
  }
  
  

};

Benchmark.prototype.teardown = function() {
  totalPaidExpensesInINR = null;

};
</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
10 Expense Items
let totalPaidExpensesInINR = tripExpenses10
    .filter(expense => expense.paid)
    .map(expense => {
        if(expense.currency == 'USD')
            return expense.amount * 70;
        else
            return expense.amount;
    })
    .reduce((amountA, amountB) => amountA + amountB);
pending…
10,000 Expense Items
let totalPaidExpensesInINR = tripExpenses10000
    .filter(expense => expense.paid)
    .map(expense => {
        if(expense.currency == 'USD')
            return expense.amount * 70;
        else
            return expense.amount;
    })
    .reduce((amountA, amountB) => amountA + amountB);
pending…
100,000 Expense Items
let totalPaidExpensesInINR = tripExpenses100000
    .filter(expense => expense.paid)
    .map(expense => {
        if(expense.currency == 'USD')
            return expense.amount * 70;
        else
            return expense.amount;
    })
    .reduce((amountA, amountB) => amountA + amountB);
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