# Rolling maxima

**URL:** <https://discourse.julialang.org/t/rolling-maxima/33845>\
**Category:** Performance\
**Created:** [January 27, 2020, 12:53pm UTC](https://discourse.julialang.org/t/rolling-maxima/33845 "2020-01-27T12:53:35Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![Jakub\_Wronowski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakub_wronowski/32/204030_2.png) [@Jakub\_Wronowski](https://discourse.julialang.org/u/Jakub_Wronowski)\
**Post date:** [January 29, 2020, 3:54pm UTC](https://discourse.julialang.org/t/rolling-maxima/33845/21 "2020-01-29T15:54:40Z")

</div>

> [@Kruxigt](#):
>
> The last one of course loses some tricks but should be very close to yours?

```julia
julia> x = rand(1000000);

julia> K = 9000;

julia> result2 = @btime movingmax($x, $K);
  21.238 ms (4 allocations: 7.58 MiB)

julia> result3 = @btime rolling_max($x, $K);
  24.017 ms (5 allocations: 7.64 MiB)

```

Yes they are close even for bigger N and K, I think the trick my algorithm is doing is no looking backward to the vector in each iteration, cause my Deque is keeping more information in a tuple. We have also a bit different memory access pattern (last/first in Deque). I have no idea why I did it this way. It is a rewrite from my old code in C#, but I recall I spent a lot of time on tuning this thing.

UPDATE: This package implements similar algorithm using custom ring buffers, it’s 2x faster than our approach.

> [@ANN: MaxMinFilters.jl - fast streaming maximum / minimum within moving window](https://discourse.julialang.org/t/ann-maxminfilters-jl-fast-streaming-maximum-minimum-within-moving-window/30151):
>
> A detailed description at: Here I’d like to ask some questions to the Julia Community: Should this package become a part of [DSP.jl](https://github.com/JuliaDSP/DSP.jl)? There are several packages in Julia with overlapping functionality: [RollingFunctions.jl](https://github.com/JeffreySarnoff/RollingFunctions.jl), [Indicators.jl](https://github.com/dysonance/Indicators.jl), [ImageFiltering.jl](https://github.com/JuliaImages/ImageFiltering.jl), should we take that moving window functions into a separate package and use it consistently in other packages? If yes, then who should take care of consistence in: a) naming for moving (sliding, running, rolling) functions (filters)? b) ho…

---

_[View the full topic](https://discourse.julialang.org/t/rolling-maxima/33845)._
