Re: about replicate_inplace [message #35898 is a reply to message #35891] |
Tue, 22 July 2003 16:42   |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"JD Smith" <jdsmith@as.arizona.edu> wrote in message
news:pan.2003.07.22.22.25.44.654998.25152@as.arizona.edu...
> If you want that array to be full of zeroes, then it looks like yes,
> but I submit this for your inspection:
>
> nreg=2000
> T = systime(1)
> b = bytarr(nreg, nreg)
> b[*]=1b
> print, systime(1) - T, ' seconds, BYTARR and [*]'
>
> T = systime(1)
> b = bytarr(nreg, nreg)
> replicate_inplace, b, 1b
> print, systime(1) - T, ' seconds, BYTARR and REPLICATE_INPLACE'
>
> T = systime(1)
> replicate_inplace, b, 1b
> print, systime(1) - T, ' seconds, REPLICATE_INPLACE'
>
> T = systime(1)
> b = make_array(/BYTE,nreg,nreg,VALUE=1b)
> print, systime(1) - T, ' seconds, MAKE_ARRAY'
>
> 0.15847003 seconds, BYTARR and [*]
> 0.027868986 seconds, BYTARR and REPLICATE_INPLACE
> 0.016924024 seconds, REPLICATE_INPLACE
> 0.021242023 seconds, MAKE_ARRAY
> Looks like REPLICATE_INPLACE is the fastest way to populate an
> existing array with 1's (or some arbitrary value, for that matter).
to populate with an arbitary value, check out
onebyte = 1b
T = systime(1)
b = bytarr(nreg, nreg)+onebyte
print, systime(1) - T, ' seconds'
> 0.029999971 seconds
compared to the above code example:
0.13000000 seconds, BYTARR and [*]
0.050000072 seconds, BYTARR and REPLICATE_INPLACE
0.039999962 seconds, REPLICATE_INPLACE
0.040000081 seconds, MAKE_ARRAY
Also, kinda interesting
T = systime(1)
b = b*zero+onebyte
print, systime(1) - T, ' seconds, *0 + 1'
gives us:
0.039999962 seconds, *0 + 1
which is the same as replciate_inplace and make_array.
just thought it was kinda interesting......
cheers,
bob
|
|
|