moment.js parse vs d3.time.parse

JavaScript performance comparison

Test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.0.1/d3.v3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/1.7.2/moment.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var ds1 = '2010-02-03T11:24:14',
        ds2 = '2010-02-03',
        d3DateTimeParser = d3.time.format.utc('%Y-%m-%dT%X').parse,
        d3DateParser = d3.time.format.utc('%Y-%m-%d').parse;
   
    function parseMoment(ds) {
      return moment.utc(ds).toDate();
    }
};
</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
Moment, datetime
var date = parseMoment(ds1);
console.assert(date.getTime() == 1265196254000);
pending…
D3, datetime
var date = d3DateTimeParser(ds1);
console.assert(date.getTime() == 1265196254000);
pending…
Moment, date
var date = parseMoment(ds2);
console.assert(date.getTime() == 1265155200000);
pending…
D3, date
var date = d3DateParser(ds2);
console.assert(date.getTime() == 1265155200000);
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