Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Too bad CPS is SLOW AS FUCK

Name: Anonymous 2011-01-28 19:08

(fact values 100000), ten times (cps)
cpu time: 431239 real time: 431781 gc time: 132998
(fact 100000), ten times (tail recursive)
cpu time: 7 real time: 6 gc time: 0

Name: Anonymous 2011-01-28 20:29

>>3
I'm not sure I understand what you're saying, but if you are not tail-calling a continuation with the results, then you don't have CPS.
Also, CPS is not intended as an optimisation.

; naive factorial
(define factorial
  (lambda (n)
    (if (< n 2)
        1
        (* n
           (factorial (- n 1))))))

; naive factorial cpsed, with cpsed primitives
(define factorial-cps
  (lambda (n k)
    (<cps n 2
          (lambda (k2)    
            (if k2
                (k 1)
                (-cps n 1
                      (lambda (k3)
                        (factorial-cps k3
                                       (lambda (k4)
                                         (*cps n k4 k))))))))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List