moment.unix() vs moment()

Benchmark created by Alien on


Description

Compare performance between moment.unix(unixTimestamp) and moment(timestamp)

Preparation HTML

<script src="http://momentjs.com/downloads/moment.min.js"></script>

Setup

var timestamps = [],
        unixTimestamps = [],
        timestamp = Date.now().valueOf(),
        unixTimestamp = Math.round(timestamp/1000);
    
    for (var i = 0; i < 10000; i++) {
        timestamps.push(timestamp++);    
        unixTimestamps.push(unixTimestamp++);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
moment.unix()
for (var i = 0, len = unixTimestamps.length; i < len; i++) {
    moment.unix(unixTimestamps[i]);
}
ready
moment()
for (var i = 0, len = timestamps.length; i < len; i++) {
    moment(timestamps[i]);
}
ready
moment.unix().format("YYYY-MM-DD")
for (var i = 0, len = unixTimestamps.length; i < len; i++) {
    moment.unix(unixTimestamps[i]).format("YYYY-MM-DD");
}
ready
moment().format("YYYY-MM-DD")
for (var i = 0, len = timestamps.length; i < len; i++) {
    moment(timestamps[i]).format("YYYY-MM-DD");
}
ready

Revisions

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