Page 1 of 1

implicit indexing performance question

Posted: Sun Apr 16, 2006 8:00 pm
by Dmi
Checking the performace of different indexing techniques, I found strange result:

Code: Select all

> (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:
Implicit 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

Posted: Sun Apr 16, 2006 8:50 pm
by Lutz
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:

Code: Select all

> (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

Posted: Sun Apr 16, 2006 8:58 pm
by Dmi
Oh sure! I done imlicit code from an nth one and miss a mistake.
Thanks :-)