# NumPy is faster than Julia 1.11 for maximum function

**URL:** <https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451>\
**Category:** General Usage\
**Tags:** performance\
**Created:** [July 3, 2025, 1:18pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451 "2025-07-03T13:18:04Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 3, 2025, 3:09pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/21 "2025-07-03T15:09:03Z")

</div>

> [@karei](#):
>
> `np.max` calls C to compute it, and it’s to be expected that it’s faster than a pure Julia implementation.

Nope! C ain’t an insurmountable barrier like the speed of light is. It’s not necessarily _able_ to natively express the fastest possible implementation for some algorithms. But, similarly, Julia might not be able to, either.

They’re all just languages that are _trying_ to give you the ability to express (and then compile to) the fastest set of instructions for a given architecture with varying levels of success.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 3, 2025, 3:12pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/22 "2025-07-03T15:12:45Z")

</div>

> [@karei](#):
>
> `np.max` calls C to compute it, and it’s to be expected that it’s faster than a pure Julia implementation.

```julia
In [2]: a = np.random.rand(512000)
In [3]: %timeit np.min(a)
44.6 µs ± 853 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops
each)

```

```julia
julia> @be rand(512000) fast_minimum samples=100 evals=50
 mean 38.949 μs

```

Julia is actually faster if you enable fastmath like Numpy does.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 3, 2025, 3:19pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/23 "2025-07-03T15:19:52Z")

</div>

> [@MilesCranmer](#):
>
> Here is the code executed for max: [numpy/numpy/\_core/src/umath/loops\_minmax.dispatch.c.src at 85708b3c0bd3d2fdbcb00cb08d0a7b323ce3af2d · numpy/numpy · GitHub](https://github.com/numpy/numpy/blob/85708b3c0bd3d2fdbcb00cb08d0a7b323ce3af2d/numpy/_core/src/umath/loops_minmax.dispatch.c.src#L317-L446)

For fun, this is the kernel internally used by Julia on v1.13 (and soon v1.12 too):

> <https://github.com/JuliaLang/julia/blob/7a5c4b5214c6a8f835cc78c48e872c0806b0f487/base/reduce.jl#L251-L273>

For all reductions, not just `min`/`max`. BTW, @mbauman [Remove bugged and typically slower `minimum`/`maximum` method by mbauman · Pull Request #58267 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/58267/files) should have deleted

> <https://github.com/JuliaLang/julia/blob/7a5c4b5214c6a8f835cc78c48e872c0806b0f487/base/reduce.jl#L250-L250>

right?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 3, 2025, 3:24pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/24 "2025-07-03T15:24:31Z")

</div>

They still _may!_ 🙂

I’m still trying to figure out how to better express this implementation in a way that’s both more generic and more easily (and perhaps even documentedly?) specializable. This may yet change in bigger ways.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 3, 2025, 3:31pm UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/25 "2025-07-03T15:31:17Z")

</div>

testing against Julia nightly:

```python
In [2]: import numpy as np
   ...:
   ...: A = np.random.rand(2026,51,251)
   ...: %timeit np.max(A)
3.71 ms ± 32.5 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

```

```julia
julia> @btime maximum(A)
  4.789 ms (0 allocations: 0 bytes)
0.9999999129587941

julia> @btime @fastmath maximum(A)
  3.531 ms (0 allocations: 0 bytes)
0.9999999129587941

```

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [July 4, 2025, 2:02am UTC](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451/26 "2025-07-04T02:02:57Z")

</div>

On my architecture (AMD), I see no improvement going from 11.5 to today’s nightly, nor of any of the alternatives suggested above. Wonder why.

[Previous page](https://discourse.julialang.org/t/numpy-is-faster-than-julia-1-11-for-maximum-function/130451.md?page=1)
