[racket] Optimization

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Jun 16 04:01:49 EDT 2014

I see these taking 3 or 4 msec each, which is hard to draw conclusions from.

Robby

On Mon, Jun 16, 2014 at 2:44 AM, Roman Klochkov <kalimehtar at mail.ru> wrote:
> (define data (for/list ([x 100000]) x))
>
> (time (begin0 (void) (run2 data)))
> (time (begin0 (void) (run1 data)))
>
> 3 times run1, then 3 times run2, then again 3 times run1.
>
> Results are stable.
>
> Mon, 16 Jun 2014 08:28:10 +0100 от Matthew Flatt <mflatt at cs.utah.edu>:
>
> I'd expect them to run nearly the same due to inlining and constant
> propagation. If I save your program to "ex.rkt" and use
>
>  raco make ex.rkt
>  raco decompile ex.rkt
>
> the the output looks almost the same for both functions.
>
> There's a lot of allocation in these programs, of course, and that's
> going to make benchmarking relatively tricky. How are you timing the
> functions, and does it matter whether you `run1` or `run2` first?
>
> At Mon, 16 Jun 2014 11:16:25 +0400, Roman Klochkov wrote:
>> Strange.
>>
>> #lang racket
>> (define (test1 x y)
>>   (if x
>>     (+ y 1)
>>     (- y 1)))
>> (define (test2 x)
>>   (if x
>>     (λ (y) (+ y 1))
>>     (λ (y) (- y 1))))
>> (define (run1 data)
>>   (map (λ (x) (test1 #t x)) data))
>> (define (run2 data)
>>   (map (λ (x) ((test2 #t) x)) data)) I expect, that run2 should be faster,
>> because (test2 #t) returns const (lambda (y) (+ y 1)) and shouldn't be
>> checked
>> on every iteration.
>>
>> But in reality (time ...) gives 219 for run1 and 212 for run2. run2 is 1.5
>> times slower!
>>
>> Why so?
>>
>>
>> --
>> Roman Klochkov____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
>
>
> --
> Roman Klochkov
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>


Posted on the users mailing list.