new Date() vs Date.setTime()

JavaScript performance comparison

Revision 3 of this test case created

Info

Compare the fastest ways to load a date from a number into a date object.

Preparation code

<script>
  var nums = [];
  for (var i = 0; i < 1000; i++) {
    nums[i] = Date.now;
  }

  var reuse_date = new Date();
</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
new Date()
var len = nums.length;
var d;
for (var i = 0; i < len; i++) {
  d = new Date(nums[i]);
}
pending…
Date.setTime()
var len = nums.length;
var d = reuse_date;
for (var i = 0; i < len; i++) {
  d.setTime(nums[i]);
}
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