Maximum!(v, A) is slower than own implementation?


I noticed that maximum!(v, A) is slower than my following implementation, I couldn’t find its implementation in Base to check my self.

function maximum2!(out,A)
	@inbounds for i = 1:length(out)
		out[i] = A[i]
    @inbounds for j = 2:size(A,2)
   	    for i = 1:size(A,1)
 			out[i] = ifelse(A[i,j] > out[i], A[i,j], out[i])

I measured the performance of both functions as follows, finding my function to be 4.2X faster:

using BenchmarkTools

const A = randn(1000,1000) 
const v = Array{Float64}(uninitialized, 1000)

@btime maximum!(v, A)
@btime maximum2!(v, A)

  1.025 ms (7 allocations: 288 bytes)
  244.020 μs (0 allocations: 0 bytes)

Do I miss something?


Similar to


Thank you, @antoine-levitt, I noticed that Jeff has already added the performance label on that issue, so I think there is no need to open a new issue for this?