Choosing the Best Order

Benchmark created by BretCameron on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

function sumCents1(array) {
    return '$' + array.map(el => el / 100).reduce((x, y) => x + y);
  };
  
  function sumCents2(array) {
    return '$' + array.reduce((x, y) => x + y) / 100;
  };
  
  const cents = [2305, 4150, 5725, 2544, 1900];

Test runner

Ready to run.

Testing in
TestOps/sec
Convert to Dollars First, Then Sum
sumCents1(cents);
ready
Sum First, Then Convert to Dollars
sumCents2(cents);
ready

Revisions

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

  • Revision 1: published by BretCameron on