guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fixes to goops + light structs + 'u' slots


From: Andy Wingo
Subject: Re: fixes to goops + light structs + 'u' slots
Date: Wed, 16 Apr 2008 00:22:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

On Sun 13 Apr 2008 21:09, "Mikael Djurfeldt" <address@hidden> writes:

> At least given the state of Guile at the point when
> GOOPS accessors were implemented, the current imlementation was
> superior to both a slot-ref-based and a SMOB-based implementation.
[...]
> In any case, *please* always benchmark changes like this against previous 
> code.

So, I was curious about this. I made four very simple tests:

accessor set:  (set! (bar instance) 3)
accessor ref:  (bar instance)
slot-set!:     (slot-set! instance 'bar 3)
slot-ref:      (slot-ref instance 'bar)

Where instance is defined as:
(define-class <cls> () (bar #:accessor bar))
(define instance (make <cls>))

I then ran the tests in that order in the order given, within this loop:

    (time (do ((i 1 (1+ i))) ((> i 1000000))  ... ))

That's the time macro from (ice-9 time).

These are my results on my Core2 Duo laptop, fixed to 800 mhz, against
the latest guile 1.8 and 1.6. The "baseline" is the do loop without any
test at all:

                   user time
               1.6          1.8
--------------+----------------------
baseline      |1.67s        1.97s
accessor set  |2.66s        3.90s
accessor ref  |2.61s        3.79s
slot-set!     |2.58s        3.80s
slot-ref      |2.23s        3.15s

I then ran accessor ref tests on objects that necessarily had their slots
bound, and thus would go through @assert-bound-ref:

(define-class <cls2> () (baz #:accessor baz #:init-value 3))
(define instance2 (make <cls2>))

                   user time
               1.6          1.8
--------------+----------------------
accessor ref  |2.22s        3.00s

Note the scale is that a single ref translates to 1 or 2 microseconds,
and this with the clock scaled back significantly. By way of comparison,
a 1000000-time ref loop in python took 0.52s, a set loop took 0.59s, and
a noop loop took 0.18s.

Conclusions:

  (1) 1.8 is slower than 1.6. (We knew that.)
  (2) The speed ordering is the same on 1.8 and 1.6:
      slot-ref < accessor ref
      slot-set! < accessor set
  (3) If the determination can be made that the slot will never be
      unbound, and we compile to the @assert-bound-ref case, then
      accessor refs are indeed faster than slot-ref.
  (4) In this particular test, guile is slower than python

I would speculate, Mikael, that it is case (3) that you are recalling.

Andy
-- 
http://wingolog.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]