[plt-dev] Apply/List vs Call-with-values/vector->values
The second is faster because an intermediate list requires more
allocation than an intermediate array of values.
(The `call-with-values' expression is compiled to an internal
`apply-values' form, so no closure is allocated in that case. Also,
`make-prefab-struct' receives its arguments in an internal array in
either case.)
At Mon, 22 Feb 2010 08:42:08 -0700, Jay McCarthy wrote:
> I guess my real question is: should I rely on this or is it a coincidence?
>
> Jay
>
> On Mon, Feb 22, 2010 at 8:40 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
> > On Mon, Feb 22, 2010 at 10:37 AM, Jay McCarthy <jay.mccarthy at gmail.com>
> wrote:
> >> How should I expect these two lines to compare performance-wise:
> >>
> >> (apply make-prefab-struct
> >> (vector->list v))
> >>
> >> vs
> >>
> >> (call-with-values (lambda () (vector->values v))
> >> make-prefab-struct)
> >
> > #lang scheme
> >
> > (define v '#(foo 1 2 3))
> >
> > (define k 1000000)
> >
> > (define (run1)
> > (for ((i (in-range k)))
> > (apply make-prefab-struct
> > (vector->list v))))
> >
> >
> > (define (run2)
> > (for ((i (in-range k)))
> > (call-with-values (lambda () (vector->values v))
> > make-prefab-struct)))
> >
> > (time (run1))
> > (time (run2))
> >
> > cpu time: 1068 real time: 1075 gc time: 60
> > cpu time: 864 real time: 866 gc time: 44
> >
> >
> >
> >
> > --
> > sam th
> > samth at ccs.neu.edu
> >
>
>
>
> --
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://teammccarthy.org/jay
>
> "The glory of God is Intelligence" - D&C 93
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-dev