# Array-making speed

• Subject: Array-making speed
• From: Ben Tupper <btupper(at)bigelow.org>
• Date: Fri, 29 Dec 2000 13:55:39 -0500
• Newsgroups: comp.lang.idl-pvwave
• Organization: Bigelow Laboratory for Ocean Sciences
• Xref: news.doit.wisc.edu comp.lang.idl-pvwave:22772

```Hello,

A (long) while back there was a discussion regarding which, of a number
of methods, was most efficient at making a blank array.  I couldn't
locate the archive at DejaNews, so I tried to figure out which one to
use by trial and error.

Below is the code I used to make an 640x480 zero-valued array with
MAKE_ARRAY, INTARR and REPLICATE.  I tried each in a loop, with the loop
incrementing to 1, 10, 100 and finally 1000 times.  The results are
shown below; note how INTARR looks non-linear when the in the 100 count
loop (I expected something between 0.16 and 0.17) .  Loopy, huh?  Just
gee-whiz enough that I thought I'd share it.

IDL> arraymaking
** Structure !VERSION, 7 tags, length=44:
ARCH            STRING    'PowerMac'
OS              STRING    'MacOS'
OS_FAMILY       STRING    'MacOS'
RELEASE         STRING    '5.4'
BUILD_DATE      STRING    'Nov  1 2000'
MEMORY_BITS     INT             32
FILE_OFFSET_BITS
INT       =       32
MakeArray x 1    0.0022699833
IntArr x 1    0.0016069412
Replicate x 1    0.0025990009

MakeArray x 10     0.023674965
IntArr x 10     0.016358972
Replicate x 10     0.023769975

MakeArray x 100      0.23571503
IntArr x 100      0.30677903
Replicate x 100      0.25714195

MakeArray x 1000       2.3778840
IntArr x 1000       1.7446461
Replicate x 1000       2.3371190

;---------------- START
PRO ArrayMaking

nx = 640
ny = 480

n = [1,10,100,1000]

Help, !Version, /str

For j = 0, 3 Do Begin

Start = SYSTIME(/Sec)
For i = 0, n[j]-1 Do D = MAKE_ARRAY(nx,ny,Value = 0)
Print, 'MakeArray x ',StrTrim(n[j],2), SYSTIME(/Sec)-Start

Start = SYSTIME(/Sec)
For i = 0, n[j]-1 Do D = IntArr(nx,ny)
Print, 'IntArr x ',StrTrim(n[j],2), SYSTIME(/Sec)-Start

Start = SYSTIME(/Sec)
For i = 0, n[j]-1 Do D = Replicate(0,nx,ny)
Print, 'Replicate x ',StrTrim(n[j],2), SYSTIME(/Sec)-Start

Print, ' '
EndFor	;j loop

END
;----------------END

Ben

--
Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd.
W. Boothbay Harbor, ME 04575
btupper@bigelow.org

```