Skip to content

Summing Complex Measurements #99

@JonasIsensee

Description

@JonasIsensee

Hi,
the following caught me by surprise...
Is there any good reason that the "true" sum function is so much more expensive?

julia> using Measurements
[ Info: Precompiling Measurements [eff96d63-e80a-5855-80a2-b1b0885c5ab7]

julia> x = rand(1000) .± rand(1000);

julia> z = complex.(x,x);

julia> @time sum(x)
  0.124190 seconds (351.04 k allocations: 18.032 MiB)
496.0 ± 18.0

julia> @time sum(z)
  2.022132 seconds (1.20 M allocations: 56.428 MiB, 1.64% gc time)
(496.0 ± 18.0) + (496.0 ± 18.0)im

julia> Base.sum(z::Array{Complex{Measurement{T}}}) where T= sum(real.(z)) .+ im*sum(imag.(z))

julia> @time sum(z)
  0.126569 seconds (321.87 k allocations: 16.926 MiB)
(496.0 ± 18.0) + (496.0 ± 18.0)im

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions