Add seconds to date

Benchmark created by Dan Peleg on


Description

Which is the fastest way of adding X seconds to Date object

Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.1/moment.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
getTime
var d = new Date('2014-01-01 10:11:55');
d = new Date(d.getTime() + 10000);
ready
setSeconds
var d = new Date('2014-01-01 10:11:55');
d.setSeconds(d.getSeconds() + 10);
ready
moment.js
var d = new moment('2014-01-01 10:11:55');
d = d.add(10, 'seconds');
ready

Revisions

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

  • Revision 1: published by Dan Peleg on