Good day, The time required to access the keys and values of an Orderedhash rises exponentially with the number of elements contained in the Orderedhash. This makes it unusable for large collections. The same is !not! true for ordinary Hash objects. With a hash the time required to access the keys and values rises approximatly linearly with the number of elements contained within the hash. This is what I would expect for an OrderedHash as well. Is this expected behaviour? Will this be fixed in future versions of IDL? If this is expected: Please make a notice in the documentation so others won't make the same mistake as I did: Using OrderedHash for large numbers of elements. ; ========================================================================================================= ; Code to visualize the issue (CAUTION: May take some minutes to execute) ; ========================================================================================================= lowest = 10L^4 largest = 10L^5 keys = INDGEN(largest) values = FINDGEN(largest) ; ========================================================================================================= ; HASH ht = LIST() hi = LIST() FOR i=lowest,largest-1,1000 DO BEGIN &$ h = HASH(keys[0:i],values[0:i]) &$ t0=SYSTIME(/SECONDS) &$ k = h.keys() &$ ht.add,SYSTIME(/SECONDS)-t0 &$ hi.add,i &$ ENDFOR time_per_element = ht.toarray()/hi.toarray() number_of_elements = hi.toarray() plot(number_of_elements,time_per_element,XTITLE="number of elements in HASH",YTITLE="time required for each element",TITLE="HASH performance") ; ========================================================================================================= ; OrderedHash oht = LIST() ohi = LIST() ; for orderedhash execute everything one magintude smaller FOR i=lowest*0.1,largest*0.1-1,1000*0.1 DO BEGIN &$ h = ORDEREDHASH(keys[0:i],values[0:i]) &$ t0=SYSTIME(/SECONDS) &$ k = h.keys() &$ oht.add,SYSTIME(/SECONDS)-t0 &$ ohi.add,i &$ ENDFOR time_per_element_oh = oht.toarray()/ohi.toarray() number_of_elements_oh = ohi.toarray() plot(number_of_elements_oh,time_per_element_oh,XTITLE="number of elements in ORDEREDHASH",YTITLE="time required for each element",TITLE="ORDEREDHASH performance")
|