Hi Simon, Simon Danisch <sdani...@gmail.com> writes: > There is a speed difference, which you can see beautifully like this: > > function _sum{T}(::Type{T}, A) > r = zero(T) > @inbounds for i in eachindex(A) > r += T(A[i]) > end > r > end >
great, thanks. My machine seems to be way slower that yours or either I run the benchmark with more elements, but certainly I can see a big improvement if working only with Int32's: ,---- | julia> x32 = rand(Int32(1):Int32(10), 10^6) | | julia> x64 = rand(Int64(1):Int64(10), 10^6) | | julia> @benchmark _sum(Int32,x32) | BenchmarkTools.Trial: | samples: 9206 | evals/sample: 1 | time tolerance: 5.00% | memory tolerance: 1.00% | memory estimate: 16.00 bytes | allocs estimate: 1 | minimum time: 529.80 μs (0.00% GC) | median time: 534.73 μs (0.00% GC) | mean time: 539.94 μs (0.00% GC) | maximum time: 873.10 μs (0.00% GC) | | julia> @benchmark _sum(Int64,x64) | BenchmarkTools.Trial: | samples: 4159 | evals/sample: 1 | time tolerance: 5.00% | memory tolerance: 1.00% | memory estimate: 16.00 bytes | allocs estimate: 1 | minimum time: 1.18 ms (0.00% GC) | median time: 1.19 ms (0.00% GC) | mean time: 1.20 ms (0.00% GC) | maximum time: 1.72 ms (0.00% GC) `---- -- Ángel de Vicente http://www.iac.es/galeria/angelv/