miniquad icon indicating copy to clipboard operation
miniquad copied to clipboard

gl.js: use performance timer

Open troyc opened this issue 3 years ago • 2 comments

Use performance.now instead of Date.now, which may provide a higher-resolution time (depending on the browser's Spectre mitigation settings). The time returned will no longer be relative to the Unix epoch and system clock.

troyc avatar Dec 14 '22 15:12 troyc

This might brake a lot of things - on all the other platforms, date::now return Unix epoch :(

not-fl3 avatar Dec 14 '22 16:12 not-fl3

I amended the commit to add performance.timeOrigin to the returned result, which should be equivalent to Date.now() with the added benefit of sub-millisecond timing for browsers that support it. I explored this possibility with the following jsfiddle:

let date = Date.now()
let now = performance.now()
//performance.timing.navigationStart is deprecated
let now2 = performance.timing.navigationStart + performance.now()
let now3 = performance.timeOrigin + performance.now()

console.log("date: " + date)
console.log("now: " + now)
console.log("now2: " + now2)
console.log("now3: " + now3)

troyc avatar Dec 14 '22 18:12 troyc