getTimestamp.js 797 B

1234567891011121314151617181920212223
  1. /**
  2. * Gets a timestamp that can be used in measuring the time between events. Timestamps
  3. * are expressed in milliseconds, but it is not specified what the milliseconds are
  4. * measured from. This function uses performance.now() if it is available, or Date.now()
  5. * otherwise.
  6. *
  7. * @exports getTimestamp
  8. *
  9. * @returns {Number} The timestamp in milliseconds since some unspecified reference time.
  10. */
  11. var getTimestamp;
  12. if (typeof performance !== 'undefined' && typeof performance.now === 'function' && isFinite(performance.now())) {
  13. getTimestamp = function() {
  14. return performance.now();
  15. };
  16. } else {
  17. getTimestamp = function() {
  18. return Date.now();
  19. };
  20. }
  21. export default getTimestamp;