Why do `$`s in BenchmarkTools change allocations so dramatically?

So I know you’ve found this thread to be a red-herring on your way to the more complicated issue you’re trying to debug, but there is a pretty straightforward answer to how BenchmarkTools uses that $ syntax. It simply constructs its benchmarking loop such that anything that’s $'ed is an argument to the function. Everything else is considered a global. How big of an effect this has is entirely dependent upon what Julia is doing.

In general, you want to make sure all function-local variables in your original example have $'s on them in their benchmarks.

2 Likes