# Nextfloat is slower on 2D array than on 1D array

**URL:** <https://discourse.julialang.org/t/nextfloat-is-slower-on-2d-array-than-on-1d-array/128380>\
**Category:** Performance\
**Created:** [April 24, 2025, 5:02pm UTC](https://discourse.julialang.org/t/nextfloat-is-slower-on-2d-array-than-on-1d-array/128380 "2025-04-24T17:02:18Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 24, 2025, 6:44pm UTC](https://discourse.julialang.org/t/nextfloat-is-slower-on-2d-array-than-on-1d-array/128380/8 "2025-04-24T18:44:22Z")

</div>

for a slightly better MWE:

```julia
julia> function test3(data::Array{Float64})
           output = copy(data)
           for i in eachindex(output)
               output[i] = nextfloat(output[i])
           end
           return output
       end
julia> @benchmark test3(arr_1D)
BenchmarkTools.Trial: 92 samples with 1 evaluation per sample.
 Range (min … max): 45.105 ms … 87.348 ms ┊ GC (min … max): 1.90% … 42.24%
 Time (median): 49.644 ms ┊ GC (median): 4.18%
 Time (mean ± σ): 54.777 ms ± 11.319 ms ┊ GC (mean ± σ): 13.74% ± 13.55%

   ▂ ▅▇█▄▄                                                     
  ▆███████▆▆▃▃▃▁▁▅▃▁▃▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▃▅▅▃▁▃▃▃▇▅▁▁▃▁▁▁▁▁▁▁▁▁▃ ▁
  45.1 ms Histogram: frequency by time 87.3 ms <

 Memory estimate: 68.66 MiB, allocs estimate: 2000006.

julia> @benchmark test3(arr_2D)
BenchmarkTools.Trial: 46 samples with 1 evaluation per sample.
 Range (min … max): 92.110 ms … 151.183 ms ┊ GC (min … max): 1.77% … 21.01%
 Time (median): 106.151 ms ┊ GC (median): 5.72%
 Time (mean ± σ): 109.749 ms ± 14.033 ms ┊ GC (mean ± σ): 10.83% ± 7.46%

     ▄▄▄▁ █▁ █ ▄ ▁▁ ▁▁                       
  ▆▁▆████▁▆▁██▆▁█▆█▁▆▆▁██▁▁▁▁▆▁▁▁▁▁▁▁▆▆▁██▁▆▁▁▆▁▁▆▁▁▁▁▁▁▁▁▁▁▁▁▆ ▁
  92.1 ms Histogram: frequency by time 151 ms <

 Memory estimate: 129.70 MiB, allocs estimate: 4000008.

```

---

_[View the full topic](https://discourse.julialang.org/t/nextfloat-is-slower-on-2d-array-than-on-1d-array/128380)._
