-
Notifications
You must be signed in to change notification settings - Fork 355
fix "zero-time measurements" bug #867
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
base: master
Are you sure you want to change the base?
Conversation
…rack down this bug where measurements are zero
|
Found another place where measurements can come out 0, while running benchmarks of my project. |
preliminary port of MachAbsoluteTime and RDPTSCP measurements from smalloc half-assed and non-compiling code to debug a bug in the RDPTSCP measurement
happy (This version still doesn't compile, but if you're a Criterion developer, you might want this patch.
and then give up and tell clippy to stop warning about that
fix the compile
…s call to it (which would cause the elapsed duration to be 0) then instead say that the elapsed duration is 1.
…e by a veeeeery small positive float instead
…me is 0 and if so setting it to 1 nanosecond
… other call site I could find in this file that computes a duration -- if the duration is < 1 then set it equal to 1.
…ments, fix a couple of docs
…act that it is not allowed to return 0; remove unit test that Criterion allows Measurements to return 0.
…urements: if it is 0, then set it to 1 nanosecond I don't 100% know that this is a problem, but I've getting irreproducible failures that mention "NaN", and I investigated and added a bunch of asserts, and determined that there are a couple of spots that divide by a number that is sometimes 0, and I guess that number might sometimes be 0 due to elapsed_time sometimes being 0. So, I don't know this is really a good fix for a specific bug, but maybe so, and it probably doesn't hurt.
…ing point numbers
src/bencher.rs
Outdated
| black_box(routine()); | ||
| } | ||
| self.value = self.measurement.end(start); | ||
| assert!(self.measurement.to_f64(&self.value) > f64::MIN_POSITIVE, "{}", self.measurement.to_f64(&self.value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this not be ">=" or just "> 0.0"?
| .first() | ||
| .unwrap(); | ||
| assert!(t_now - t_prev > f64::MIN_POSITIVE); | ||
| let t = (t_prev + 2. * t_now) / 5.; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using "git rebase -i HEAD~23" you can change this commit to a fixup of your first commit.
| [lints.clippy] | ||
| uninlined_format_args = "allow" | ||
|
|
||
| [dependencies] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps move the format_arg changes to a separate PR?
|
@zooko you should really clean up the commit history and remove temporary debug stuff and merge fixup commits with the commit they fix up. Also separate out all unrelated stuff, like clippy fixes. Perhaps then this stands a chance of being accepted. |
| #[cfg(target_arch = "x86_64")] | ||
| pub mod plat_x86_64 { | ||
| use cpuid; | ||
| use crate::{Throughput, Measurement}; | ||
| use crate::measurement::ValueFormatter; | ||
| use core::arch::x86_64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there some reshuffling of modules?
| /// A slightly better timer for Apple platforms. | ||
| pub mod plat_apple { | ||
| use mach_sys::mach_time::mach_absolute_time; | ||
| use mach_sys::mach_time::{mach_absolute_time, mach_timebase_info}; | ||
| use mach_sys::kern_return::KERN_SUCCESS; | ||
| use crate::measurement::ValueFormatter; | ||
| use std::mem::MaybeUninit; | ||
| use crate::{Measurement, Throughput}; | ||
|
|
||
| #[derive(Default)] | ||
| struct MachAbsoluteTimeMeasurement { } | ||
| /// Use the `mach_absolute_time()` clock, which is slightly better | ||
| /// in my [tests](https://github.com/zooko/measure-clocks) than | ||
| /// `Instant::now()`. | ||
| pub struct MachAbsoluteTimeMeasurement { } | ||
|
|
||
| struct MachAbsoluteTimeValueFormatter { } | ||
|
|
||
| use mach_sys::mach_time::mach_timebase_info; | ||
| use mach_sys::kern_return::KERN_SUCCESS; | ||
| /// Formatter | ||
| pub struct MachAbsoluteTimeValueFormatter { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt?
src/measurement.rs
Outdated
| } | ||
| fn end(&self, i: &Self::Intermediate) -> Self::Value { | ||
| ( unsafe { mach_absolute_time() } - i ) | ||
| ( unsafe { mach_absolute_time() } - i ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt?
| fn lt(&self, val: &Self::Value, other: &Self::Value) -> bool { | ||
| val < other | ||
| } | ||
| fn debugprint(&self, val: &Self::Intermediate, other: &Self::Value) { | ||
| eprintln!("val: {val:?}, other: {other:?}"); | ||
| } | ||
| fn to_f64(&self, val: &Self::Value) -> f64 { | ||
| *val as f64 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt?
This fixes #862