[plt-scheme] Making a fast list like sequence

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Apr 7 19:18:31 EDT 2009

At Tue, 07 Apr 2009 19:09:27 -0400, David Van Horn wrote:
> Matthew Flatt wrote:
> > At Tue, 07 Apr 2009 18:32:33 -0400, David Van Horn wrote:
> >> I see dramatic differences in running times between the built-in list 
> >> sequence and a naive implementation of list sequencing.  What can I do 
> >> to make this naive implementation run faster?
> > 
> > If you use use `car', `cdr', and `pair? instead of `first', `rest', and
> > `(compose not empty?)', you should get the same performance as for
> > lists.
> 
> This didn't improve the running time very much.  It's still not nearly 
> as fast as just a direct list value.
> 
> Here are the timings for a list sequence built with car/cdr/pair?, a 
> list-like structure sequence, a direct list, and an list in in-list:
> 
> cpu time: 2036 real time: 2327 gc time: 0
> cpu time: 2179 real time: 2387 gc time: 0
> cpu time: 686 real time: 720 gc time: 0
> cpu time: 690 real time: 694 gc time: 0

How are you running this (platform, environment, language, etc.)?

I didn't pay attention to the scale of your numbers versus mine before,
but even in DrScheme with debugging enabled in the Module language for
v4.1.5 on Mac OS X, I get much smaller numbers:

 cpu time: 16 real time: 16 gc time: 0
 cpu time: 20 real time: 25 gc time: 0
 cpu time: 22 real time: 22 gc time: 0
 cpu time: 1 real time: 1 gc time: 0




Posted on the users mailing list.