This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Rational numbers?


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]