Performance penalty of `>(1)` vs `x -> x >1`?

Whatever is causing this slowdown, I don’t see it happen with a more naive summation:

# Julia Version 1.10.0-DEV.579
# Commit 76557783da (2023-02-11 02:16 UTC)

julia> x = randn(1000);

julia> function myintsum(f,x)
               s = 0
               for xx in x
                       s += f(xx)
               end
               return s
       end
myintsum (generic function with 1 method)

julia> @btime sum(x->x>1,$x)
  67.042 ns (0 allocations: 0 bytes)
173

julia> @btime sum(>(1),$x)
  308.502 ns (0 allocations: 0 bytes)
173

julia> @btime myintsum(x->x>1,$x)
  63.878 ns (0 allocations: 0 bytes)
173

julia> @btime myintsum(>(1),$x)
  63.776 ns (0 allocations: 0 bytes)
173
1 Like