ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.2k stars 142 forks source link

Reduce iterations in concatenate! #946

Closed ekaitz-zarraga closed 6 months ago

ekaitz-zarraga commented 6 months ago

This commit should reduce the amount of iterations in concatenate to N where N is the sum of the lengths of the input lists.

The previous implementation iterated from the beginning in each concatenation because of last-pair.

This implementation is significantly faster in this extreme case:

(concatenate! `(,(iota 50000) ,@(map list (iota 500))))

Previous implementation: real 0m0.671s user 0m0.658s sys 0m0.013s

This implementation: real 0m0.175s user 0m0.174s sys 0m0.001s

The tests is done using time, which is not reliable at all, but using (trace last-pair) shows accurately what happens with the iterations.