Understanding Allocations and Views

Does it need to allocate to hold tmp .* pre_allocated_tuple? How about a generator?

julia> using BenchmarkTools

julia> a = rand(3); b = rand(3)                                                                           
                                                                                               
julia> @btime sum($a .* $b)                                                                               
  24.900 ns (1 allocation: 80 bytes)                                                                      
6.25852e-01                                                                                               
                                                                                                         
julia> @btime sum($a[i] * $b[i] for i in 1:length($a))                                                    
  5.900 ns (0 allocations: 0 bytes)                                                                       
6.25852e-01                                                                                               
1 Like