Skip to content

Inefficient access of structure array within a structure #2188

@rsiddans

Description

@rsiddans

GDL is very very slow (compared to IDL) at accessing individual elements of a large structure array held within another structure.
I.e. this
for i=0,n-1 do m1=x.m(i)
Is drastically slower than
m=x.m & for i=0,n-1 do m1=m(i)

It is as if GDL copies the entire (sub)structure array before accessing the individual structure, rather than directly access the element itself.

Code to test this...

pro test_strarr_access
; make a big array of structures
        m1={a:10}
        n=50000l
        m=replicate(m1,n)
; Time accessing each structure in turn
        t0=systime(/jul)
        for i=0,n-1 do m1=m(i)
        t1=systime(/jul)
        print,'Time to access m: '+string((t1-t0)*24*60*60)+'s'
; Time accessing each structure in turn when the array is inside another structure
        x={m:m}
        t0=systime(/jul)
        for i=0,n-1 do m1=x.m(i)
        t1=systime(/jul)
        print,'Time to access m in structure: '+string((t1-t0)*24*60*60)+'s'
end

Output with IDL and GDL

GDL> test_strarr_access
Time to access m: 0.0053107738s
Time to access m in structure: 22.644134s

IDL> test_strarr_access
% Compiled module: TEST_STRARR_ACCESS.
Time to access m: 0.0037014484s
Time to access m in structure: 0.0088512897s

Note the behaviour of GDL is much better for a simple integer array - e.g. defining "m1=10" instead of "m1={a:10}". The issue seems specific to structure arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions