Last active
October 27, 2015 09:39
-
-
Save LiuJi-Jim/9596920 to your computer and use it in GitHub Desktop.
HRT(High Resolution Timing) in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hrtime = (function(){ | |
if (typeof window !== 'undefined'){ | |
// browser | |
if (typeof window.performance !== 'undefined' && typeof performance.now !== 'undefined'){ | |
// support hrt | |
return function(){ | |
return performance.now(); | |
}; | |
}else{ | |
// oh no.. | |
return function(){ | |
return (new Date()).getTime(); | |
}; | |
} | |
}else{ | |
// node.js | |
return function(){ | |
var diff = process.hrtime(); | |
return (diff[0] * 1e9 + diff[1]) / 1e6; // nano second -> ms | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
谢谢,正好需要。