Skip to content

Commit 2cc81ac

Browse files
committed
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.
1 parent 3d5fbae commit 2cc81ac

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libtest/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,10 +1332,11 @@ impl MetricMap {
13321332
/// elimination.
13331333
///
13341334
/// This function is a no-op, and does not even read from `dummy`.
1335-
pub fn black_box<T>(dummy: T) {
1335+
pub fn black_box<T>(dummy: T) -> T {
13361336
// we need to "use" the argument in some way LLVM can't
13371337
// introspect.
13381338
unsafe {asm!("" : : "r"(&dummy))}
1339+
dummy
13391340
}
13401341

13411342

0 commit comments

Comments
 (0)