This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Rational numbers?
- To: hjstein at bfr dot co dot il (Harvey J. Stein)
- Subject: Re: Rational numbers?
- From: Mikael Djurfeldt <mdj at thalamus dot nada dot kth dot se>
- Date: 12 Nov 1999 20:19:39 +0100
- Cc: Greg Harvey <Greg dot Harvey at thezone dot net>, hanwen at cs dot uu dot nl, guile at sourceware dot cygnus dot com, djurfeldt at nada dot kth dot se
- Cc: djurfeldt at nada dot kth dot se
- References: <14380.7634.150220.183840@dokkum.cs.uu.nl> <xy7so2bssye.fsf@mdj.nada.kth.se> <m33dubhdm2.fsf@behemoth.dethfart.org> <kiwiu37ejsf.fsf@blinky.bloomberg.com>
- Reply-to: Mikael Djurfeldt <djurfeldt at nada dot kth dot se>
hjstein@bfr.co.il (Harvey J. Stein) writes:
> Unless goops has impossibly good function dispatch I'd expect you'll
> get a substantial performance hit on general arithemtic by doing this.
It has...
(And in a way I find it slightly boring that I have to point out this
myself.)
Regard the following code:
Here's a procedure version of summing integers:
(define (p+ x y)
(+ x y))
(define (p- x y)
(- x y))
(define (procedure-sum n res)
(if (zero? n)
res
(procedure-sum (p- n 1) (p+ 1 res))))
And here's the corresponding GOOPS code, with 3 dispatches on two
arguments per turn in the loop.
(define-method gf+ ((x <number>) (y <number>))
(+ x y))
(define-method gf- ((x <number>) (y <number>))
(- x y))
(define-method generic-sum ((n <number>) (res <number>))
(if (zero? n)
res
(generic-sum (gf- n 1) (gf+ 1 res))))
As shown by the benchmark which I've put into Jim's benchmark suite,
the type dispatch gives an additional overhead of just a few percent.
But of course we should make a careful benchmark before replacing the
current code.