Local versus Peer

JavaScript performance comparison

Test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    utilities = function() {};
    utilities.dateDiffA = function(datepart, fromdate, todate) {
      datepart = datepart.toLowerCase();
      var diff = todate - fromdate;
      var divideBy = {
        y: 31536000000,
        m: 2628000000,
        w: 604800000,
        d: 86400000,
        h: 3600000,
        n: 60000,
        s: 1000
      };
   
      return Math.ceil(diff / divideBy[datepart]);
    };
    utilities.divideBy = {
      y: 31536000000,
      m: 2628000000,
      w: 604800000,
      d: 86400000,
      h: 3600000,
      n: 60000,
      s: 1000
    };
   
    utilities.dateDiffB = function(datepart, fromdate, todate) {
      datepart = datepart.toLowerCase();
      var diff = todate - fromdate;
   
      return Math.ceil(diff / this.divideBy[datepart]);
    };
    var choices = 'ymwdhns';
    var todate = new Date('6/19/2013 23:46:03');
    var fromdate = new Date('3/23/2011 11:33:02');
   
    utilities.prototype.dateDiffC = function(datepart, fromdate, todate) {
      datepart = datepart.toLowerCase();
      var diff = todate - fromdate;
      var divideBy = {
        y: 31536000000,
        m: 2628000000,
        w: 604800000,
        d: 86400000,
        h: 3600000,
        n: 60000,
        s: 1000
      };
   
      return Math.ceil(diff / divideBy[datepart]);
    }
   
    utilities.prototype.divideByProto = {
      y: 31536000000,
      m: 2628000000,
      w: 604800000,
      d: 86400000,
      h: 3600000,
      n: 60000,
      s: 1000
    };
   
    utilities.prototype.dateDiffD = function(datepart, fromdate, todate) {
      datepart = datepart.toLowerCase();
      var diff = todate - fromdate;
   
      return Math.ceil(diff / this.divideByProto[datepart]);
    }
   
    var utility = new utilities();
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Local
for (var i = 0; i < 7; i += 1) {
  utilities.dateDiffA(choices[i], fromdate, todate);
}
pending…
Peer
for (var i = 0; i < 7; i += 1) {
  utilities.dateDiffB(choices[i], fromdate, todate);
}
pending…
Shared Prototype Local
for (var i = 0; i < 7; i += 1) {
  utility.dateDiffC(choices[i], fromdate, todate);
}
pending…
Shared Prototype Peer
for (var i = 0; i < 7; i += 1) {
  utility.dateDiffD(choices[i], fromdate, todate);
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment