I'm trying to measure something, but I'm getting rug-pulled by the compiler. While I appreciate its attempts at making my code run faster, I need a reliable way of preventing it from erasing my benchmarks. I have tried using the following blackHole(_:) function, but I observed no change in behavior. Is there a tried and true benchmarking strategy?
@inline(never) func blackHole(_ value: some Any) { } // 😞
Hm. Using the function from a different module does not seem to help, in my case, but @_semantics("optimize.no.crossmodule") appears to prevent complete erasure. I assume SPM enables cross-module optimization by default? I saw it used in swift/.../TestsUtils.swift and adopted the underscored and stringly typed attribute in true cargo cult fashion. @_optimize(none) also seems to prevent complete erasure, but I'm unsure how it differs.
How do we feel about exposing a public blackhole function in the standard library? This seems to come up every so often, and it's needlessly tricky to get right