I don't know the answer for sure, but I expect it has to do with the
fact that loop2 is defined at the top-level in the REPL. Putting that
into a module, I see this:


☕  racket ~/tmp2.rkt
cpu time: 3155 real time: 3222 gc time: 0
500000000500000000
cpu time: 2979 real time: 3045 gc time: 0
500000000500000000
☕  cat ~/tmp2.rkt
#lang racket/base
(define (test1)
  (define (loop s i)
    (if (> i 1000000000) s (loop (+ s i) (+ i 1))))
  (loop 0 1))

(define (loop2 s i)
  (if (> i 1000000000) s (loop2 (+ s i) (+ i 1))))

(define (test2)
  (loop2 0 1))

(time (test1))
(time (test2))

On Tue, Jun 9, 2015 at 9:24 PM, Roman Klochkov <kalimehta...@gmail.com> wrote:
> Inner procedure call is 3 times faster
>
> $ racket
> Welcome to Racket v6.1.1.
>> (define (test1)
>       (define (loop s i)
>         (if (> i 1000000000) s (loop (+ s i) (+ i 1))))
>   (loop 0 1))
>
>> (define (loop2 s i)
>      (if (> i 1000000000) s (loop2 (+ s i) (+ i 1))))
>
>> (define (test2)
>      (loop2 0 1))
>
>> (time (test1))
> cpu time: 6764 real time: 6775 gc time: 0
> 500000000500000000
>> (time (test2))
> cpu time: 14584 real time: 14527 gc time: 0
> 500000000500000000
>
> Is it should be so?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to