# Why is copying using a loop is much slower than \`copy\` for large arrays?

**URL:** <https://discourse.julialang.org/t/why-is-copying-using-a-loop-is-much-slower-than-copy-for-large-arrays/90633>\
**Category:** Performance\
**Tags:** question, copy\
**Created:** [November 22, 2022, 9:24am UTC](https://discourse.julialang.org/t/why-is-copying-using-a-loop-is-much-slower-than-copy-for-large-arrays/90633 "2022-11-22T09:24:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [November 22, 2022, 1:37pm UTC](https://discourse.julialang.org/t/why-is-copying-using-a-loop-is-much-slower-than-copy-for-large-arrays/90633/2 "2022-11-22T13:37:03Z")

</div>

A possible explaination :  
The builtin-in copy simply calls a builtin function `jl_array_copy`, which in turn calls a builtin array constructor and `memcpy` function. Your simple implementation cannot beat C’s highly optimized memcpy (memcpy is really smart and it can sometimes even utilize special feature offered by operating system). The case of small array may be related to alignment problem or overhead in memcpy, since you copy directly and LLVM knows more information, some logic in memcpy can be skipped.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-copying-using-a-loop-is-much-slower-than-copy-for-large-arrays/90633)._
