Skip to content

mapslices performance #26868

@gideonsimpson

Description

@gideonsimpson

Consider the following piece of code:

n=10^6;
X = randn(1,n);
V(x) = 0.5 * dot(x,x);
f(V, X) = [ V((@view X[:,n])) for n = 1:size(X,2) ]

Timing on this reveals:

julia> @time mapslices(V, X, 1);
  1.177690 seconds (12.00 M allocations: 267.024 MiB, 6.91% gc time)
julia> @time f(V,X);
  0.047745 seconds (1.00 M allocations: 53.406 MiB, 5.58% gc time)

which is substantially different.

Note that in this simple example, my data could be a column vector; however, this is a surrogate for problems where I have time series data and X is d x n with 1< d << n.

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