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

**URL:** <https://discourse.julialang.org/t/maximum-v-a-is-slower-than-own-implementation/9512>\
**Category:** Performance\
**Created:** [March 5, 2018, 4:16pm UTC](https://discourse.julialang.org/t/maximum-v-a-is-slower-than-own-implementation/9512 "2018-03-05T16:16:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 5, 2018, 4:16pm UTC](https://discourse.julialang.org/t/maximum-v-a-is-slower-than-own-implementation/9512/1 "2018-03-05T16:16:17Z")

</div>

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

```julia
function maximum2!(out,A)
	@inbounds for i = 1:length(out)
		out[i] = A[i]
	end 
    @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])
 		end  
    end 
    out
end 

```

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

```julia
using BenchmarkTools

srand(1234)
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?

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [March 5, 2018, 4:49pm UTC](https://discourse.julialang.org/t/maximum-v-a-is-slower-than-own-implementation/9512/2 "2018-03-05T16:49:31Z")

</div>

Similar to [https://github.com/JuliaLang/julia/issues/26003](https://github.com/JuliaLang/julia/issues/26003)?

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 5, 2018, 5:37pm UTC](https://discourse.julialang.org/t/maximum-v-a-is-slower-than-own-implementation/9512/3 "2018-03-05T17:37:23Z")

</div>

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?
