Array Operations

Benchmark created by asleepysamurai on


Setup

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)]
      });
  }

Teardown



            totalPaidExpensesInINR = null;
        
  

Test runner

Ready to run.

Testing in
TestOps/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);
ready
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);
ready
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);
ready

Revisions

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

  • Revision 1: published by asleepysamurai on