Skip to content

Instantly share code, notes, and snippets.

@tk3369
Created November 23, 2019 20:45
Show Gist options
  • Save tk3369/d13ac124edb58466103cc81c6933bc57 to your computer and use it in GitHub Desktop.
Save tk3369/d13ac124edb58466103cc81c6933bc57 to your computer and use it in GitHub Desktop.
Performance result - cartesian product of two arrays
julia> foo(x,y) = reshape(collect(Iterators.product(x,y)), :, 1)
foo (generic function with 1 method)

julia> bar(x,y) = [(i,j) for j in y for i in x]
bar (generic function with 1 method)

julia> x = rand(100); y = rand(100);

julia> @btime foo($x,$y);
  15.964 μs (6 allocations: 156.47 KiB)

julia> @btime bar($x,$y);
  111.661 μs (119 allocations: 515.95 KiB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment