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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Feb 22 11:04:29 EST 2010

So we really need an apply/vector so that Jay can write

  (apply/vector make-prefab-struct v)

And for keywords, perhaps we should have an apply/hash if
we can stick keywords into the domain of a hash.

-- Matthias



On Feb 22, 2010, at 11:01 AM, Matthew Flatt wrote:

> 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
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-dev



Posted on the dev mailing list.