Skip to content

Poor performance for linspace #13401

@stevengj

Description

@stevengj

This seems odd to me:

julia> f(X) = [sin(x) + x^2 - 3 for x in X]
       x = linspace(0,1,10^7)
       @time f(x);
  0.286351 seconds (6 allocations: 76.294 MB, 0.21% gc time)

julia> x = collect(x)
       @time f(x);
  0.085037 seconds (6 allocations: 76.294 MB, 5.49% gc time)

I can understand why e.g. x.^2 might be slower for a linspace, since the computation is so cheap compared to computing the elements of the linspace on the fly, but I don't understand why a more complex operation like this, in a comprehension where the elements are calculated only once per computation, is so much slower.

See also the mailing list discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions