-
Notifications
You must be signed in to change notification settings - Fork 0
/
now.js
44 lines (34 loc) · 1006 Bytes
/
now.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function(global, define){
'use strict';
define(function(require){
// based on https://github.com/meryn/performance-now
var loadTime;
function getNanoSeconds(){
var hr = global.process.hrtime();
return hr[0] * 1e9 + hr[1];
}
if(global.performance && global.performance.now){
return global.performance.now;
}
if(global.process && global.process.hrtime){
loadTime = getNanoSeconds();
return function(){
return (getNanoSeconds() - loadTime) / 1e6;
};
}
if(Date.now){
loadTime = Date.now();
return function(){
return Date.now() - loadTime;
};
}
loadTime = new Date().getTime();
return function(){
return new Date().getTime() - loadTime;
};
});
}(
typeof global == 'object' ? global : this.window || this.global,
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
// Boilerplate for AMD and Node
));