Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gl.js: use performance timer #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

troyc
Copy link

@troyc troyc commented Dec 14, 2022

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.

@not-fl3
Copy link
Owner

not-fl3 commented Dec 14, 2022

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

Use performance.now instead of Date.now, which may provide a
higher-resolution time (depending on the browser's Spectre mitigation
settings). Add performance.timeOrigin so that the returned value is
still relative to the Unix epoch.
@troyc
Copy link
Author

troyc commented Dec 14, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants