On Sep 26, 2012, at 12:21 , Tridib Bandopadhyay <lists / ruby-forum.com> =
wrote:

> I was wondering why Ruby takes long time to create an array. I tried:
>=20
> Start =3D Time.now
> names =3D Array.new(614400000)
> puts Time.now-Start
>=20
> Ruby took around 308 seconds to create this large array. Can anyone =
tell
> me why Ruby takes such a long time? Also when assigning a variable to
> the array takes long time. Why is that?


That's invariably swap... MUUUCH slower to access a disk than memory.

On a machine with enough memory it takes about the same amount of time =
to do equivalent work:

	% /usr/bin/time -l ruby19 -e 'Array.new(614400000)'
	        2.74 real         0.88 user         1.82 sys
	4919554048  maximum resident set size
	...
	         0  swaps
	...
=09
	% cc -O3 -Wall -pedantic -std=3Dc99 woot.c && /usr/bin/time -l =
./a.out
	2.92 real 1.22 user 1.69 sys=20
	4915695616  maximum resident set size
	...
	         0  swaps
	...

where woot.c is:

	typedef unsigned long VALUE;
=09
	int main() {
	  size_t count =3D 614400000;
	  VALUE * names =3D (VALUE*)malloc(count * sizeof(VALUE));
=09
	  for(int i =3D 0; i < count; i++) {
	    names[i] =3D 4;
	  }
=09
	  free(names);
	}