[racket] Optimization

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Mon Jun 16 03:22:14 EDT 2014

 Yet more strange

(define (run3 data)
  (map (test2 #t) data))

runs twice faster. (time ...) gives only 100.

I thought, that (lambda (x) (k x)) and k -- are synonims and optimizer elide extra lambda.



Mon, 16 Jun 2014 11:16:25 +0400 от Roman Klochkov <kalimehtar at mail.ru>:
>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

-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140616/35ed7bca/attachment-0001.html>

Posted on the users mailing list.