[plt-dev] Apply/List vs Call-with-values/vector->values

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Feb 22 10:42:08 EST 2010

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


Posted on the dev mailing list.