comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » speed of n_elements
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
speed of n_elements [message #17664] Wed, 03 November 1999 00:00
Pavel Romashkin is currently offline  Pavel Romashkin
Messages: 166
Registered: April 1999
Senior Member
I have found the n_elements was dramatically slowing down my programs.
Specifically, I had an array of structures (450 elements) that I examine
for length in the code. Structures have 4 fields of fltarr(900) and some
scalar fields, which adds up to a substantial dataset. Obtaining the
number of elements in the array of structures was very slow (0.1 s) and
caused severe performance degradation after I called it too many times(I
probably should have just saved the array size in widget tree State
structure but I never thought that n_elements would slow me down and too
lazy to go back and change it all). However, there is a workaround that
turned out to be simple:

temp = fltarr(1000)
one_record = {ch1:temp, ch2:temp, ch3:temp, ch4:temp, flag:0L, temp:0.0,
press:0.0}
data = replicate(one_record, 450)
temp = n_elements(data) ; Very slow. Temp = 450
temp = n_elements(Data.Flag) ; Very fast. Temp = 450

So, briefly: if you want to get the size of an array of structures,
examine the size of an array of scalar fields (if available) and you
will have 10X5 faster n_elements.

Cheers,
Pavel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: What do you think of VIP?
Next Topic: MPEG2 Reader/Decoder

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 19:24:47 PDT 2025

Total time taken to generate the page: 0.24296 seconds