# Lazy or efficient representation of \`repeat\` function on Arrays?

**URL:** https://discourse.julialang.org/t/lazy-or-efficient-representation-of-repeat-function-on-arrays/73356
**Category:** General Usage
**Tags:** lazy-evaluation
**Created:** [December 20, 2021, 4:32am UTC](https://discourse.julialang.org/t/lazy-or-efficient-representation-of-repeat-function-on-arrays/73356 "2021-12-20T04:32:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)
#### Post date: [December 20, 2021, 4:32am UTC](https://discourse.julialang.org/t/lazy-or-efficient-representation-of-repeat-function-on-arrays/73356/1 "2021-12-20T04:32:56Z")

</div>

what is the best( lazy ? ) way to represent `repeat` function (other than doing following) the following

```julia
julia> @btime A = repeat([1 2],3,1)
  116.760 ns (2 allocations: 192 bytes)
3×2 Matrix{Int64}:
 1 2
 1 2
 1 2

```

i have tried LazyArray pkg , but then usual way seems more better.

```julia
using LazyArrays
a=[1,2,3];
julia> @btime @~ repeat(a,3,1)
  516.128 ns (5 allocations: 160 bytes)
Applied(repeat,[1, 2, 3],3,1)

julia> @btime repeat(a,3,1)
  170.044 ns (3 allocations: 224 bytes)
9×1 Matrix{Int64}:
 1
 2
 3
 1
 2
 3
 1
 2
 3

```

for larger arrays, lazyarrays does the job ! (so i might consider this as solution, unless we find even better solution ?)

```julia
julia> a=rand(100);

julia> @btime repeat(a,3,1);
  954.824 ns (3 allocations: 2.59 KiB)

julia> @btime @~ repeat(a,3,1);
  466.862 ns (5 allocations: 160 bytes)

```
