Hi Lindsay,

> # append
> : (bench (let (N ()) (for X 10000 (setq N (append N '(NIL)))) (length N)))
> 0.548 sec
> -> 10000
> 
> # cons
> : (bench (let (N '()) (for X 10000 (setq N (cons NIL N))) (length N)))
> 0.000 sec
> -> 10000

'append' in such a loop is a lot slower than a straightforward 'cons', because
'cons' creates only a single new cell and puts it in front of the existing list,
while 'append' makes a copy of the whole list (as it is non-destructive) and
then 'conc's the new cell.


> # conc
> : (bench (let (N (list)) (for X 9999 (conc N (list))) (length N)))
> 0.067 sec
> -> 10000
> ...
> Interestingly, I was expecting conc to be faster then (setq..(cons..). At
> least in this case, it was not.
> 
'conc' avoids the copying, but still traverses the (longer and longer) list each
time.


To build really long lists it is better to use (make ... (link ...))

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to