process.hrtime polyfill
(function() { | |
const nowOffset = Date.now(); | |
const now = () => Date.now() - nowOffset; | |
global.process.hrtime = global.process.hrtime || ((previousTimestamp) => { | |
const baseNow = Math.floor((Date.now() - now()) * 1e-3) | |
const clocktime = now() * 1e-3 | |
let seconds = Math.floor(clocktime) + baseNow | |
let nanoseconds = Math.floor((clocktime % 1) * 1e9) | |
if (previousTimestamp) { | |
seconds = seconds - previousTimestamp[0] | |
nanoseconds = nanoseconds - previousTimestamp[1] | |
if (nanoseconds < 0) { | |
seconds-- | |
nanoseconds += 1e9 | |
} | |
} | |
return [seconds, nanoseconds] | |
}) | |
})() |
!function(){const o=Date.now(),t=()=>Date.now()-o;global.process.hrtime=global.process.hrtime||(o=>{const e=Math.floor(.001*(Date.now()-t())),n=.001*t();let a=Math.floor(n)+e,l=Math.floor(n%1*1e9);return o&&(a-=o[0],l-=o[1],l<0&&(a--,l+=1e9)),[a,l]})}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Based on https://github.com/cabinjs/browser-hrtime/blob/master/src/index.ts
Minified by https://xem.github.io/terser-online/