# Time needed to append an array element

**URL:** <https://www.ruby-forum.com/t/time-needed-to-append-an-array-element/134406>\
**Category:** Ruby\
**Created:** [April 10, 2008, 3:45pm UTC](https://www.ruby-forum.com/t/time-needed-to-append-an-array-element/134406 "2008-04-10T15:45:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercan01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mercan01](https://www.ruby-forum.com/u/mercan01)\
**Post date:** [April 10, 2008, 3:45pm UTC](https://www.ruby-forum.com/t/time-needed-to-append-an-array-element/134406/1 "2008-04-10T15:45:32Z")

</div>

How does the time to append an element to an array depend on the size of  
the array? Is it practical to build up a large array one element at a  
time? Note that for a naive implementation that copies the array for  
each element appended, the time required would be proportional the the  
square of the final size of the array.

Thanks  
Bill Rutiser

---

<div class="post-metadata">

**Author:** ![mercan01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@mercan01](https://www.ruby-forum.com/u/mercan01)\
**Post date:** [April 10, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/time-needed-to-append-an-array-element/134406/2 "2008-04-10T17:51:24Z")

</div>

On Thu, Apr 10, 2008 at 9:44 AM, William R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How does the time to append an element to an array depend on the size of  
> the array?

[http://ruby-doc.org/stdlib/libdoc/benchmark/rdoc/index.html](http://ruby-doc.org/stdlib/libdoc/benchmark/rdoc/index.html)

–  
Avdi

Home: [http://avdi.org](http://avdi.org)  
Developer Blog: [http://avdi.org/devblog/](http://avdi.org/devblog/)  
Twitter: [http://twitter.com/avdi](http://twitter.com/avdi)  
Journal: [http://avdi.livejournal.com](http://avdi.livejournal.com)
