Thanks @pdeffebach . However this kind of strategy is analogous to the _test
barrier, which doesn’t solve my problem.
The following is promising, though:
julia> import FunctionWrappers
julia> import FunctionWrappers: FunctionWrapper
julia> struct S
f::FunctionWrapper{Bool,Tuple{Float64}}
end
julia> test(s::S, r::Float64) = s.f(r)
test (generic function with 1 method)
julia> x = S(FunctionWrapper{Bool,Tuple{Float64}}(r -> r < 0.5));
julia> function run(s::S)
z = 0
for _ in 1:1e5
r = rand()
z += test(s, r)
end
return z
end
run (generic function with 1 method)
julia> using BenchmarkTools; @btime run($x)
601.449 μs (0 allocations: 0 bytes)
Maybe the trick is to wrap everything inside a test::FunctionWrapper
…