Return passed value from black_box
By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away.
This commit is contained in:
parent
3d5fbae338
commit
2cc81ac531
@ -1332,10 +1332,11 @@ pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) {
|
||||
/// elimination.
|
||||
///
|
||||
/// This function is a no-op, and does not even read from `dummy`.
|
||||
pub fn black_box<T>(dummy: T) {
|
||||
pub fn black_box<T>(dummy: T) -> T {
|
||||
// we need to "use" the argument in some way LLVM can't
|
||||
// introspect.
|
||||
unsafe {asm!("" : : "r"(&dummy))}
|
||||
dummy
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user