On 20/02/18 00:08, Vítor De Araújo wrote:
We can try this out:
scheme@(guile-user)> (use-modules (system base compile))
scheme@(guile-user)> (define exp '(lambda (n)
(let loop ([i n] [total 0])
(if (= i 0)
total
(loop (1- i) (+ i total))))))
scheme@(guile-user)> (define f1 (eval exp (interaction-environment)))
scheme@(guile-user)> (define f2 (compile exp #:env
(interaction-environment)))
scheme@(guile-user)> ,time (f1 1000000)
$2 = 500000500000
;; 0.845240s real time, 0.895351s run time. 0.071494s spent in GC.
scheme@(guile-user)> ,time (f2 1000000)
$3 = 500000500000
;; 0.067317s real time, 0.067278s run time. 0.000000s spent in GC.
So the answer does seem to be "yes": the compiled procedure is much
faster.
Thanks. A 10X speedup is just what the doctor ordered.
As it happened, I was looking for a way to time functions, and didn't
realise that guile has a convenient way of doing this.