Skip to content

Commit

Permalink
timer: change new Date to Date.now for performance
Browse files Browse the repository at this point in the history
Speeds up benchmark/settimeout.js by about 30%.
  • Loading branch information
Shigeki Ohtsu authored and bnoordhuis committed Jul 10, 2012
1 parent f210530 commit 76104f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var lists = {};
// the main function - creates lists on demand and the watchers associated
// with them.
function insert(item, msecs) {
item._idleStart = new Date();
item._idleStart = Date.now();
item._idleTimeout = msecs;

if (msecs < 0) return;
Expand All @@ -71,8 +71,8 @@ function insert(item, msecs) {
list.ontimeout = function() {
debug('timeout callback ' + msecs);

var now = new Date();
debug('now: ' + now);
var now = Date.now();
debug('now: ' + (new Date(now)));

var first;
while (first = L.peek(list)) {
Expand Down Expand Up @@ -155,7 +155,7 @@ exports.active = function(item) {
if (!list || L.isEmpty(list)) {
insert(item, msecs);
} else {
item._idleStart = new Date();
item._idleStart = Date.now();
L.append(list, item);
}
}
Expand Down

0 comments on commit 76104f3

Please sign in to comment.