Oso wrote: Thu Sep 28, 2023 9:11 am
Interesting demonstration of how PB is very fast at moving sequentially through List elements, but not so at random access. If you happen to traverse through the list sequentially though, or at least less randomly than the example, then this index method 1 becomes slower than PB's native SelectElement() — see below. We may need a bounds check, depending on usage, which slows it down only very slightly, otherwise it enters an infinite loop if the element doesn't exist. Very interesting though and of course all depends on the need.
Code: Select all
; Fast Test
For i = 0 To #DataSize
SelectElementFast(MyData(), MyIndex(), i)
Next
[...]
For i = 0 To #DataSize
SelectElement(MyData(), i)
Next
999999 [sequential ] seek (Indexed) Time =1436ms
999999 [sequential ] (Ordinary) Time =12ms
For the bounds check, I needed to add the below, otherwise a missing element caused it to go on forever...
Code: Select all
K = Predict * #Index_Step
While K < ID ; <---- And K < 999999
IF NextElement(MainList())
K+1
ENDIF
Wend
Hi , Oso , please note that ,
Code: Select all
SelectElement Doc:
As lists don't use an index internally, this function will jump compulsory to every element in the list until the target position is reached which will take time if the list is large. If a faster method is needed, ChangeCurrentElement() should be used.
the original selectelement() is not fast , and not make for sequential access . it is make for Random access , but it is slow in design seems it has no index build in , what i do is implement a index to boost the selectelement() speed , so call selectelementfast().
for any other things that need a sequential access , please use FOREACH/NEXT , or While NextElement() Wend .
this is what it make for.
thanks and best regards guy.