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
1 changed files with 2 additions and 1 deletions
|
|
@ -1332,10 +1332,11 @@ impl MetricMap {
|
|||
/// 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…
Add table
Add a link
Reference in a new issue