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?


Mikael Djurfeldt <mdj@thalamus.nada.kth.se> writes:

 > 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...

<snip>

 > 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.

First of all, this is comparing interpreted function dispatch vs goops
dispatch.  It might be very close when comparing corresponding code,
but I was talking about comparing +/- to gf+/gf-, because it seemed
that the previous msg was talking about rewriting the numerical
routines so that the different types of numbers are goops classes &
the numerical operators are using goops dispatch.  So, the comparison
I'd like to see is for the current numberical fcns vs goops wrapped
versions, as in:

   (define-method gf+ ((x <small-exact>) (y <small-exact>))
      (+ x y))
   (define-method gf+ ((x <small-exact>) (y <bignum>))
      (+ x y))
   (define-method gf+ ((x <small-exact>) (y <inexact>))
      (+ x y))
  etc.

Of course, this is unfair to goops because of the double dispatching
(goops *and* internal arithmetic vs just goops).  What I was thinking
of was if you exposed the internal type specific fcns and did
something like:

   (define-method gf+ ((x <small-exact>) (y <small-exact>))
      (ss+ x y))
   (define-method gf+ ((x <small-exact>) (y <bignum>))
      (sb+ x y))
   (define-method gf+ ((x <small-exact>) (y <inexact>))
      (si+ x y))
   (define-method gf+ ((x <bignum>) (y <small-exact>))
      (sb+ y x))
   (define-method gf+ ((x <bignum>) (y <bignum>))
      (bb+ x y))
   (define-method gf+ ((x <bignum>) (y <inexact>))
      (bi+ x y))
   (define-method gf+ ((x <inexact>) (y <small-exact>))
      (si+ y x))
   (define-method gf+ ((x <inexact>) (y <bignum>))
      (bi+ y x))
   (define-method gf+ ((x <inexact>) (y <inexact>))
      (ii+ x y))

and then compare + to gf+.

-- 
Harvey Stein
Bloomberg LP
hjstein@bfr.co.il

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