Dear all, I was testing some acceleration of for loops (and reducing the allocations), and I made a less complex example for testing:
Julia>julia> function test_1(a,b)
@views for i in 1:a, j in 1:b
c = i + j
end
end
test_1 (generic function with 1 method)
julia> @benchmark test_1(5,5)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
Range (min … max): 1.500 ns … 8.291 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 1.583 ns ┊ GC (median): 0.00%
Time (mean ± σ): 1.566 ns ± 0.084 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
▇ █▁
▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂ ▂
1.5 ns Histogram: frequency by time 1.62 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> function test_2(a,b)
for i in 1:a, j in 1:b
c = i + j
end
end
test_2 (generic function with 1 method)
julia> @benchmark test_2(5,5)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
Range (min … max): 1.500 ns … 6.792 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 1.583 ns ┊ GC (median): 0.00%
Time (mean ± σ): 1.566 ns ± 0.076 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
▇ █▁
▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂ ▂
1.5 ns Histogram: frequency by time 1.62 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
Shouldn’t I expect the function test_1
to be faster due to the usage of @views
?