You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sharing my analysis about an issue I have encountered. Although I manage to fix my specific usecase, I'd like to have some feedback before trying to open a PR to propose a more global fix.
Context
I wanted to make some performance measurement, and I realized that I had a milliseconds precision.
My test basically relies on this kind of code structure:
let a = Instant::now();
....
let b = Instant::now();let d = b.duration_since(a).as_micros();
log::info!("{:?} => {:?}: {}", a, b, d.as_micros());
the timestamps returned by performance.now() are not limited to one-millisecond resolution. Instead, they represent times as floating-point numbers with up to microsecond precision
Dirty prototyping
I have patched quickly the library to try to keep the millisecond precision in my specific codepath:
diff --git a/src/std.rs b/src/std.rs
index 7c88189..fee6573 100644
--- a/src/std.rs+++ b/src/std.rs@@ -112,9 +112,9 @@ impl Sub<Instant> for Instant {
type Output = Duration;
fn sub(self, other: Instant) -> Duration {
- let ms = self.inner - other.inner;- assert!(ms >= 0.0);- Duration::from_millis(ms as u64)+ let d = self.inner - other.inner;+ assert!(d >= 0.0);+ Duration::from_micros((d * 1000.0) as u64)
}
}
I'm sharing my analysis about an issue I have encountered. Although I manage to fix my specific usecase, I'd like to have some feedback before trying to open a PR to propose a more global fix.
Context
I wanted to make some performance measurement, and I realized that I had a milliseconds precision.
My test basically relies on this kind of code structure:
Here is the kind of result is get:
performance.now()
theoretical precisionAccording to https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#performance.now_vs._date.now:
Dirty prototyping
I have patched quickly the library to try to keep the millisecond precision in my specific codepath:
Result:
The text was updated successfully, but these errors were encountered: