Re: Arrays suck. Loops rock. [message #43139 is a reply to message #42948] |
Mon, 14 March 2005 16:46  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Tue, 08 Mar 2005 11:51:22 -0800, Y.T. wrote:
>
>> IDL> test_loop,findgen(300,300,10),findgen(10,20),disps,nloops=0
>> took 1.1159251 sec
>> IDL> test_loop,findgen(300,300,10),findgen(10,20),disps,nloops=1
>> took 0.96256900 sec
>> IDL> test_loop,findgen(300,300,10),findgen(10,20),disps,nloops=2
>> took 2.0543392 sec
>> IDL> test_loop,findgen(300,300,10),findgen(10,20),disps,nloops=4
>> took 27.267108 sec
>>
>
>
> I'd like to add to this that I sure hope you guys didn't just run each
> call once -- for then the results you get are utterly arbitrary. At the
> level of a sizable fraction of a second the OS can throw stuff at you
> for no better reason than that it is tuesday. On your first call, IDL
> has to allocate a lot of memory, for example, which it may or may not
> free up and thus it may or may not be faster on the second call. Any
> memory allocation may or may not proceed swiftly depending on how much
> cleanup the OS has to do before it can hand IDL the requisite amount of
> memory. And so forth.
>
> Thus for any kind of timing comparisons you'll always want to re-run
> the routine in question at least a couple times (ideally something like
> 1000 times from a loop and then compute the average). Otherwise you're
> measuring OS latency because of a big TCP packet that happened to hit
> your ethernet port just that moment (or similar things) rather than the
> actual speed of the algorithm.
But of course. In addition to that caveat, the major warning that any
given timing comparison may be completely invalid on another system should
be made.
> (I honestly fail to understand the provided example and am not at all
> sure that the two "rebins" are necessary. You are aware that 'rebin'
> performs interpolations, right?)
Here REBIN is used in a bit of a non-intuitive way, simply to
replicate data in arrays along additional dimensions. Used with
/SAMPLE (and in recent versions of IDL, by default), it never tries to
perform any sort of interpolation, despite that being its primary use.
This functionality could probably be split out into another more
aptly-named routine at a huge gain in readability. But then people
might discover how to do it by reading the manuals, and that would be
worrisome.
JD
|
|
|