Abdulaziz Ghuloum wrote:
I get:
$ ikarus -O2 --r6rs-script /tmp/fib.ss
running stats for (fib 34):
no collections
157 ms elapsed cpu time, including 0 ms collecting
159 ms elapsed real time, including 0 ms collecting
0 bytes allocated
Just to summarize, the times for standard, FP-style, and using binrec, with:
(cp0-size-limit (* 2 (cp0-size-limit)))
in '.ikarusrc' are:
~ # ikarus -O2 --r6rs-script /scratch/_fib-a.scm
running stats for (fib 34):
no collections
304 ms elapsed cpu time, including 0 ms collecting
304 ms elapsed real time, including 0 ms collecting
0 bytes allocated
~ # ikarus -O2 --r6rs-script /scratch/_fib-fp-a.scm
running stats for (fib 34):
no collections
324 ms elapsed cpu time, including 0 ms collecting
323 ms elapsed real time, including 0 ms collecting
0 bytes allocated
~ # ikarus -O2 --r6rs-script /scratch/_fib-binrec-a.scm
running stats for (fib 34):
no collections
832 ms elapsed cpu time, including 0 ms collecting
832 ms elapsed real time, including 0 ms collecting
0 bytes allocated
Sources included.
Ed
----------------------------------------------------------------------
(import (rnrs)
(ikarus))
(define (fib n)
(if (<= n 1)
1
(+ (fib (- n 1))
(fib (- n 2)))))
(time (fib 34))
----------------------------------------------------------------------
(import (rnrs)
(ikarus))
(define (bi f g c)
(lambda (x)
(c (f x)
(g x))))
(define (uni f c)
(lambda (x)
(c (f x))))
(define (sub x)
(lambda (y)
(- y x)))
(define (constant x)
(lambda (y)
x))
(define (ifte f g h)
(lambda (x)
(if (f x)
(g x)
(h x))))
(define (less-than= x)
(lambda (y)
(<= y x)))
(define fib
(ifte (less-than= 1)
(constant 1)
(bi (uni (sub 1) (lambda (x) (fib x)))
(uni (sub 2) (lambda (x) (fib x))) +)))
(time (fib 34))
----------------------------------------------------------------------
(import (rnrs) (ikarus))
(define (binrec f g h i j)
(define (fun x)
(if (f x)
(g x)
(j (fun (h x))
(fun (i x)))))
fun)
(define (constant x)
(lambda (y)
x))
(define (less-than= x)
(lambda (y)
(<= y x)))
(define (sub x)
(lambda (y)
(- y x)))
(define fib
(binrec (less-than= 1)
(constant 1)
(sub 1)
(sub 2)
+))
(time (fib 34))
----------------------------------------------------------------------