EXCEPTION_ACCESS_VIOLATION on Windows but not MacOS

Your setup argument isn’t doing what you intend to; you’re creating a namedtuple instead of a block containing two expressions. As a result, the actual benchmark is grabbing local_patch and err from global scope, which explains your allocation. The fix is to insert a semicolon in place of the comma, as follows:

julia> @benchmark sum(local_patch[i] * err[i] for i in eachindex(local_patch, err)) setup=(local_patch = fill(0.5,3,3); err = fill(0.4,3,3))

You should adjust the other benchmarking expressions similarly, and make sure you do not interpolate ($) variables that are created during setup, in other words, you should not use $ at all in these benchmarks.

Just to be sure, do this in a fresh Julia session where you have not created variables named local_patch and err in the global scope.

You should see significantly smaller numbers, especially for the versions that only have a single allocation in your current benchmarks.