# Fast 4D argmax

**URL:** https://discourse.julialang.org/t/fast-4d-argmax/58566
**Category:** Performance
**Tags:** tullio
**Created:** [April 4, 2021, 6:10pm UTC](https://discourse.julialang.org/t/fast-4d-argmax/58566 "2021-04-04T18:10:27Z")
**Posts on this page:** 1
**Showing post:** 22

<div class="post-metadata">

### Author: ![jroon](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jroon](https://discourse.julialang.org/u/jroon)
#### Post date: [April 5, 2021, 5:26pm UTC](https://discourse.julialang.org/t/fast-4d-argmax/58566/22 "2021-04-05T17:26:36Z")

</div>

@mkitti - great suggestion - here is my R code and results now:

```julia
# Make an array
n = 20 ; nx = 400 ; v = 40 ; d = 3 
array4d <- array( runif(n*nx*v*d ,-1,0),
                  dim = c(n, nx, v, d) )
#Assign to Julia
julia_assign("A", array4d)

microbenchmark:: microbenchmark(
  res1 <- which_max_4D(array4d),
  res2 <- julia_eval("whichmax4D1(A)", "R"),
  res3 <- julia_eval("whichmax4D2(A)", "R"),
  res4 <- julia_eval("whichmax4Dmap(A)", "R"),
  res5 <- julia_eval("whichmax4Dreduce(A)", "R"),
  res6 <- julia_eval("whichmax4Dtullio(A)", "R"),
  res7 <- julia_eval("whichmax4D5_leandro(A)", "R"),
  res8 <- julia_eval("whichmax4D5_elrod(A)", "R"),
  res9 <- julia_eval("whichmax4D6(A)", "R"),
  res10 <- whichmaxC(array4d), times=500)

```

 ![Screenshot 2021-04-05 at 19.23.18](https://global.discourse-cdn.com/julialang/original/3X/2/4/249e946df1de0ea0474ec90ecfead62460bf2aac.png)

Wow!! 😃

I also ran a benchmark on the `julia_assign` command:

 ![Screenshot 2021-04-05 at 19.24.27](https://global.discourse-cdn.com/julialang/original/3X/e/0/e0c200846dbcecfeebc082a5f94d801771ac276e.png)

Looks like you are right @mkitti - the slow part is moving the data from R to Julia

Edit: I ran it on an even bigger array also:

 ![Screenshot 2021-04-05 at 22.36.44](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f728697fdcfb01fe39a7ca25f874bde3667294a.png)

---

_[View the full topic](https://discourse.julialang.org/t/fast-4d-argmax/58566)._
