# Findmax on ranges

**URL:** <https://discourse.julialang.org/t/findmax-on-ranges/11870>\
**Category:** Performance\
**Created:** [June 21, 2018, 7:41pm UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870 "2018-06-21T19:41:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 21, 2018, 7:41pm UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870/1 "2018-06-21T19:41:18Z")

</div>

This had me surprised:

```julia
julia> @btime findmax($(2:10^9))
  1.191 s (0 allocations: 0 bytes)
(1000000000, 999999999)

julia> @btime maximum($(2:10^9))
  4.441 ns (0 allocations: 0 bytes)
1000000000

```

Apparently, `findmax` / `argmax` actually iterate over each element of the range. This is the case on both 0.6 and 0.7, so I’m wondering if it’s deliberate.

---

<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:** [June 21, 2018, 7:42pm UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870/2 "2018-06-21T19:42:24Z")

</div>

Definitely not deliberate, just a case of a missing optimization method. A pull request to fix this should be relatively simple and would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [June 22, 2018, 8:41am UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870/3 "2018-06-22T08:41:01Z")

</div>

I have taken a look at [CONTRIBUTING.md](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md). Unfotunately, forking and building is too high a hurdle now (implementing the code itself is not a problem.)

But I seem to remember that someone said you can create pull requests directly via the web interface with no fork/build process before that, and that this was far easier. I cannot find anything about that in CONTRIBUTING.

---

<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:** [June 22, 2018, 3:28pm UTC](https://discourse.julialang.org/t/findmax-on-ranges/11870/4 "2018-06-22T15:28:45Z")

</div>

Yes, you can definitely test it locally and then copy it into the GitHub editor. We should add directions about that to CONTRIBUTING. It definitely works best for documentation improvements; for code changes it can be more cumbersome as those almost always require editing two or more files (one for the functionality, one for the tests), but it’s still doable if you’re tenacious:

- Navigate to the code you want to modify or find similar code to what you want to add on GitHub. Using a Julia notebook here can be convenient since `@which` will give you links directly to GitHub. In this case, somewhere around [`maximum`](https://github.com/JuliaLang/julia/blob/master/base/range.jl#L454) seems like a good home.

- Click the little ✏ icon on the top of the page to bring up the GitHub editor. Scroll back down to where you were.

- Add your new functionality or make your edits.

- Scroll down to the bottom and commit your changes to a new branch. Give it a good title and description. Hit commit! Now you’ve created a branch that contains your changes.

- Here’s where it gets tricky: GitHub thinks you’re done, so it goes directly to a “Create New PR” page. But we still need to add tests to a different file. GitHub does _not_ make this easy. I think the best way is to just create the PR with the new feature, and then add a note that you’re still in the process of adding tests.

- Now go your your Julia fork (e.g., `github.com/DNF/julia`, or whatever your GitHub username is), and on [the branch dropdown menu](https://discourse.julialang.org/uploads/short-url/5PLsvM0LGShd0sl1NFhHWHYHPq5.png) find your new branch that you just created. By switching to this branch now you can add additional commits directly to it.

- Navigate to the test file you want to modify within that branch on your fork (test/ranges.jl), find a reasonable place to put your tests, copy them in, and then commit them. This time, instead of creating another branch, you want to commit them directly to the branch you’re currently on. By doing so, they’ll show up in the PR over at JuliaLang/julia.

So, yeah, it’s a bit of a pain when there’s more than one file involved.
