I'm trying to benchmark sorting runtime as a function of input size. I have this function
using BenchmarkTools
function f(n)
x = rand(Int, n)
target = sort(x)
y = copy(target)
@belapsed sort!($y) setup=($y == $target || error("Bad sort"); copyto!($y, $x)) evals=1 gctrial=false samples=3
end
But that function is a significant memory leak (because of JuliaLang/julia#14495)
If I run times = f.(1594323:1594323+100) (100 data points), it leaks about 3.56 GB according to my OS's report of how much memory the Julia process is using. Repeated runs continue to leak until my system crashes.
Is there a way to run @belapsed without leaking memory?