a curious "benckmark"

From: Brian Denheyer <briand_at_deldotd.com>
Date: Thu, 18 Mar 1999 12:25:15 -0800 (PST)

I was writing a program, and as I usually do I just immediately
started writing classes for the data structures. However I would like
this algorithm to be fairly efficient so I started wondering about the
efficiency of slot access. Strange that I never though of doing this

here are the results :

using slot accessors
;; Time: 7400.00ms
;; GC time: 1383.33ms
;; Cells: 1150250

using slot-ref
;; Time: 5016.67ms
;; GC time: 166.67ms
;; Cells: 150119

using vectors
;; Time: 1533.33ms
;; GC time: 183.33ms
;; Cells: 150118

using lists
;; Time: 1433.33ms
;; GC time: 183.33ms
;; Cells: 150119

Code is at the end of the e-mail. So a few things I was wondering
about :

Class accessors are 5x slower than vector accesses ? Is this dynamic
binding which is causing the problem, i.e. there is no guarantee that
there is only one min-x method so there is a lot of overhead in the
method look-up, or is it something else ? I thought that slot
accesses would be memoized in some way and so wouldn't suffer too

list-ref for n <= 4 is slightly FASTER than vector access ?

Is my benchmark valid or is it misguided in some way. Looks like if
you really need speed, better not use a class. True ?

Anyway, I was surprised, so I'm just wondering about how the
implementation impacts the performance.



;; benchmark to test the speed of accessing vector vs the speed of
;; accessing slots.

(define-class <square> ()
   ;; cordinates of upper right corner
   (min-x :accessor min-x
          :init-keyword :min-x)
   (min-y :accessor min-y
          :init-keyword :min-y)
   (max-x :accessor max-x
          :init-keyword :max-x)
   (max-y :accessor max-y
          :init-keyword :max-y)))

(define square (make <square> :min-x 1 :max-x 5 :min-y 3 :max-y 4))
(define x (vector 1 4 2 10))
(define y '(1 4 2 10))

(define *n* 50000)

 (do ((i 0 (+ i 1)))
     ((> i *n*))
   (+ (min-x square) (max-x square) (max-y square) (min-y square))))

 (do ((i 0 (+ i 1)))
     ((> i *n*))
   (+ (slot-ref square 'min-x)
       (slot-ref square 'max-x)
       (slot-ref square 'min-y)
       (slot-ref square 'max-y) )))

 (do ((i 0 (+ i 1)))
     ((> i *n*))
   (+ (vector-ref x 0) (vector-ref x 1) (vector-ref x 2) (vector-ref x 3))))

 (do ((i 0 (+ i 1)))
     ((> i *n*))
   (+ (list-ref y 0) (list-ref y 1) (list-ref y 2) (list-ref y 3))))
Received on Thu Mar 18 1999 - 21:27:52 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST