implicit indexing performance question

Started by Dmi, April 16, 2006, 01:00:23 PM

Previous topic - Next topic

Dmi

Checking the performace of different indexing techniques, I found strange result:
> (time
>   (dotimes (i 10000)
>     (dotimes (j 200)
>       (set 'b (nth j a)))))
1927
> (time
>   (dotimes (i 10000)
>     (dotimes (j 200)
>       (set 'b (j a)))))
55874

'a is a list of 200 one-space elements.



But documentation says:
QuoteImplicit indexing is slightly faster then indexing using nth and can take an unlimited number of indexes.

When 'a is a string of 200 spaces, then the difference is less dramatic - nth is only about 1.5 times faster.



Interesting, that slice and implicit slice timings has no such difference either for lists and strings.



newlisp ver. is 8.8.0-p2
WBR, Dmi

Lutz

#1
In your first example you are indexing but in your second example you are slicing, which is much slower because you are creating a new (up to 200 elements) list.



It shoould be (a j) not (j a). If you do (a j) it looks like this for me:



> (set 'a (sequence 1 200))

> (time (dotimes (i 1000) (dotimes (j 200) (set 'b (nth j a))))) ; indexing
217
> (time (dotimes (i 1000) (dotimes (j 200) (set 'b (a j))))) ; indexing
212
> (time (dotimes (i 1000) (dotimes (j 200) (set 'b (j a))))) ; slicing
2262
>


Lutz

Dmi

#2
Oh sure! I done imlicit code from an nth one and miss a mistake.

Thanks :-)
WBR, Dmi