@check_allocs sum_args(args...) = sum(args)
for x=1:1000
v = collect(1:x)
s = sum_args(v...)
println("sum(1:$(x)) = ", s)
end
This code will compile 1000 different (non-allocating) copies of foo, where typically Julia would typically limit the expansion to just one or two extra arguments.
For comparison, this code without @check_allocs is many, many times faster:
@noinline sum_args(args...) = sum(args)
for x=1:1000
v = collect(1:x)
s = sum_args(v...)
println("sum(1:$(x)) = ", s)
end
This code will compile 1000 different (non-allocating) copies of
foo, where typically Julia would typically limit the expansion to just one or two extra arguments.For comparison, this code without
@check_allocsis many, many times faster: