implicit indexing performance question

For the Compleat Fan
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

implicit indexing performance question

Post 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
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Oh sure! I done imlicit code from an nth one and miss a mistake.
Thanks :-)
WBR, Dmi

Locked