Skip to content

maximum() / minimum() is slow #28849

@ZeppLu

Description

@ZeppLu
julia> using BenchmarkTools; const X = rand(1000, 1000);

julia> maximum(X); @benchmark maximum(X)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     2.502 ms (0.00% GC)
  median time:      2.591 ms (0.00% GC)
  mean time:        2.764 ms (0.00% GC)
  maximum time:     6.094 ms (0.00% GC)
  --------------
  samples:          1806
  evals/sample:     1

julia> minimum(X); @benchmark minimum(X)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     2.581 ms (0.00% GC)
  median time:      2.591 ms (0.00% GC)
  mean time:        2.620 ms (0.00% GC)
  maximum time:     3.688 ms (0.00% GC)
  --------------
  samples:          1906
  evals/sample:     1

julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

Compared to python:

In [1]: import numpy as np; X = np.random.random([1000, 1000])

In [8]: %timeit np.max(X)
558 µs ± 45.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [9]: %timeit np.min(X)
467 µs ± 4.99 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIndicates that a maintainer wants help on an issue or pull requestperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions