OxL Reference

fn black_box

Returns x unchanged while hiding it from the optimizer, so that a benchmark's work is not optimized away (D-7053).

Example:

oxl✓ checked in CI
use std.test { black_box }

test bench "sum of a range" {
  let n = black_box(1000)
  var s = 0
  for i in 0..n { s += i }
  black_box(s)
}
@intrinsic("test.blackBox") pub(api) fn black_box<T>(x: T) -> T

Complexity. O(1).

Since. 1.0.0-beta

Parameters

NameType
xT

Returns

T

Effects

none declared (pure unless the body says otherwise)

Defined in: std/test/test.oxl:428

See also