Julia 1.0.2 reapeat function cost many times than matlab‘s repmat

There are a few issues with the Julia script. For example, You are pre-allocating and then replacing the object rather than using an in-place operation.

julia> using BenchmarkTools
julia> obj = rand(1_000);
julia> @benchmark repeat($obj, 50, 30)
BenchmarkTools.Trial: 
  memory estimate:  11.44 MiB
  allocs estimate:  2
  --------------
  minimum time:     1.728 ms (0.00% GC)
  median time:      2.897 ms (0.00% GC)
  mean time:        2.594 ms (27.99% GC)
  maximum time:     63.665 ms (96.94% GC)
  --------------
  samples:          1924
  evals/sample:     1
2 Likes