fastest time maths

JavaScript performance comparison

Test case created by tomByrer

Info

To test if I can perf a stopwatch timer by removing divides & pre-calcualting maths.

Tested results from old to new

Preparation code

<script src="//cdn.jsdelivr.net/lodash/2.4/lodash.min.js"></script>
<script>aryGetTime = [ 1396476687153,1396471980120,1396470937752,1396471986472,1396470958909,1396473725664,1396470937390,1396474202915,1396476692368,1396470899449,1396473888545,1396476678570,1396470910118,1396473790910,1396474121035,1396474191235,1396472077153,1396470947841,1396470950468,1396470949141,1396476690423,1396470895616,1396473886843,1396472078088,1396474189994,1396476684056,1396470934704,1396470959781,1396470908731,1396475505613,1396470915450,1396472078909,1396470904031,1396473732046,1396470944645,1396473887726,1396471979361,1396474195565,1396473790068,1396476643183,1396474197030,1396474122577,1396471982797,1396474123370,1396470906691,1396476644336,1396474190538,1396470945739,1396471978625,1396470940544,1396474199271,1396476645152,1396476676439,1396476679691,1396474191797,1396473726511,1396470893169,1396473728398,1396470897123,1396474121847,1396470898516,1396470916917,1396470933632,1396470911677 ];</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
original
_(aryGetTime).each(function(t) {
  var time = t;
  var mins = Math.floor(t / (1000*60));
  t = t % (1000*60);
  var secs = Math.floor(t / 1000);
  console.log(time + ' ' + mins + ' ' + secs);
});
pending…
Optimized
_(aryGetTime).each(function(t) {
  var time = t;
  var mins = Math.floor(t *  0.000016666666666666667); // = t / (1000 * 60)
  t = t % (60000); // 1000 * 60
  var secs = Math.floor(t * 0.001);  // t / 1000
  console.log(time + ' ' + mins + ' ' + secs);
});
pending…

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

Compare results of other browsers

0 comments

Add a comment