senchalabs/connect — Issue #420: staticCache could use Date.now
Author: manast
Created: 2011-11-22 09:47:02+00:00
State: open

Hello,

I have seen that new Date is used instead of Date.now. According to http://jsperf.com/date-now-perf
Date.now is almost x2 faster than new Date, which makes sense because you skip a memory allocation.

Furthermore, the following snippet can be written much simpler:

```javascript
header.Age = age = (new Date - new Date(header.date)) / 1000 | 0;
header.date = new Date().toUTCString();
```

would become:

```javascript
header.Age = age = (Date.now() - header.date) / 1000 | 0;
header.date = Date.now()
```

Which would be much faster because only two calls to Date.now are needed and also you skip a probably expensive parsing (and generation) of a UTC date string.

regards!.