[racket] Y-combinator perfomance

From: Groshev Dmitry (a2alt at ya.ru)
Date: Fri Jun 25 14:07:31 EDT 2010

I've mistyped. In fact things are even worse.
#lang racket
(define-syntax U
  (syntax-rules ()
    [(_ f) (f f)]))
(define-syntax define/comb
  (syntax-rules ()
    [(_ comb name (arg . args) f)
     (define name 
       (comb (λ (name) (λ (arg . args) f))))]))

(define (Z f)
  (U (λ (g) (λ x
              (apply (f (U g)) x)))))

(define/comb Z comb-sum (l t) 
  (if (empty? l) t (comb-sum (rest l) (+ t (first l)))))

(define (sum l t)
  (if (empty? l) t (sum (rest l) (+ t (first l)))))

(time (comb-sum (make-list 10000000 1) 0))
(time (sum (make-list 10000000 1) 0))
Result:
cpu time: 9922 real time: 10007 gc time: 3323
10000000
cpu time: 2762 real time: 2783 gc time: 469
10000000


Posted on the users mailing list.