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

Quanta Clock is off by a factor of 1000 in web browsers #71

Closed
vargad opened this issue Jul 13, 2022 · 0 comments · Fixed by #72
Closed

Quanta Clock is off by a factor of 1000 in web browsers #71

vargad opened this issue Jul 13, 2022 · 0 comments · Fixed by #72
Labels
bug Something isn't working

Comments

@vargad
Copy link
Contributor

vargad commented Jul 13, 2022

window.performance.now() return milliseconds. As Instant is in nanoseconds, it needs to be multiplied by 1.000.000 not 1.000.

Example to demonstrate the problem:

#[wasm_bindgen]
pub struct TestQuanta
{
    last_time: quanta::Instant
}

#[wasm_bindgen]
impl TestQuanta
{
    #[wasm_bindgen(constructor)]
    pub fn new() -> Self
    {
        Self{last_time: quanta::Instant::now()}
    }

    #[wasm_bindgen(method)]
    pub fn time_since_last_call(&mut self) -> f64
    {
        let now = quanta::Instant::now();
        let elapsed = now.duration_since(self.last_time);
        self.last_time = now;
        elapsed.as_millis() as f64
    }
}
let test_quanta = new TestQuanta();
setInterval(() => console.log(`elapsed: ${test_quanta.time_since_last_call()}ms`), 3000);

Selection_110

Expected: log something around 3000ms, as interval is called every 3000ms.

@tobz tobz added the bug Something isn't working label Jul 14, 2022
@tobz tobz closed this as completed in #72 Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants