home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mitech!gjc
- From: gjc@mitech.com (George J. Carrette)
- Newsgroups: comp.lang.scheme
- Subject: Summary. Interpreters are faster than I thought
- Message-ID: <4094@mitech.com>
- Date: 17 Dec 92 12:21:03 GMT
- Organization: Mitech Corporation, Concord MA
- Lines: 93
-
- A good deal of private email has come in on the speed of
- interpreters issue. Most with benchmarks of interpreters
- that are faster than SIOD. In fact I was most impressed by
- some results with SCM that had (standard-fib 20) running a
- good 3.8 times faster, and SCM is still an s-expression
- interpreter although it has been extended with some tricks
- that remind me a bit of the pdp-10 maclisp coded scheme
- interpreter that was used at MIT around 1980 for the
- last 6.031 classes ever, and I think the first 6.001 classes.
-
- In summary. Some scheme interpreters are pretty close to being only 3
- times slower than compiled code. Therefore interpreters are indeed
- as fast or faster than compiled code on machines from a couple years
- ago.
-
- -----------------------------
-
- FIB has always been a favorite benchmark of many people, probably
- because it is easy to count operations but not entirely trivial.
-
- However, it tends to bring up the issue of numeric optimizations,
- which can be hairy and distracting.
-
- So here is another version of fib that uses binary arithmetic
- implemented as lists of symbols. It runs around 50 times slower
- than using built-in arithmetic.
-
- ;-*-mode:lisp-*-
- ; a fib benchmark that uses binary arithmetic.
- ; 16-DEC-92 George Carrette. GJC@MITECH.COM
- ; Wanted a benchmark that avoided built-in numbers
- ; and that did more work.
- ;
- ; Benchmark: (b->number (b-fib '(A A B A B))) => 6765
- ;
- ; Note: (b->number '(A A B A B)) => 20
- ;
- ; (C) Copyright 1992 George Carrette. As described in SLIB.C
-
- (define (b-fib x)
- (if (b< x '(A B))
- x
- (b+ (b-fib (b- x '(B)))
- (b-fib (b- x '(A B))))))
-
- (define (b->number x)
- (if (null? x)
- 0
- (+ (if (eq? (car x) 'B) 1 0)
- (* 2 (b->number (cdr x))))))
-
- (define (b+ x y)
- (if (null? x)
- y
- (if (null? y)
- x
- (if (eq? (car x) 'A)
- (cons (car y) (b+ (cdr x) (cdr y)))
- (if (eq? (car y) 'A)
- (cons 'B (b+ (cdr x) (cdr y)))
- (cons 'A (b+ (b+ '(B) (cdr x)) (cdr y))))))))
-
- (define (b- x y)
- (if (null? y)
- x
- (if (null? x)
- (error "negative number")
- (if (eq? (car y) 'A)
- (bA-cons (car x) (b- (cdr x) (cdr y)))
- (if (eq? (car x) 'B)
- (bA-cons (if (eq? (car y) 'B) 'A 'B) (b- (cdr x) (cdr y)))
- (cons 'B (b- (b- (cdr x) '(B)) (cdr y))))))))
-
- (define (bA-cons x l)
- (if (and (null? l) (eq? x 'A))
- '()
- (cons x l)))
-
- (define (b< x y)
- (if (null? x)
- (not (null? y))
- (or (b< (cdr x) (cdr y))
- (if (equal? (cdr x) (cdr y))
- (if (eq? (car x) 'A)
- (eq? (car y) 'B))))))
-
-
-
-
-
-
-
-
-