| Line | |
|---|
| 1 | ;;; Some simple micro-benchmarks for CLOS. |
|---|
| 2 | ;;; |
|---|
| 3 | ;;; From: Kiczales and Rodriguez Jr., "Efficient Method Dispatch in PCL" |
|---|
| 4 | |
|---|
| 5 | (defun fun (x) 0) |
|---|
| 6 | |
|---|
| 7 | (defclass c1 () |
|---|
| 8 | ((x :initform 0 |
|---|
| 9 | :accessor accessor1 |
|---|
| 10 | :accessor accessor2 |
|---|
| 11 | :accessor accessor3))) |
|---|
| 12 | |
|---|
| 13 | (defclass c2 (c1) |
|---|
| 14 | ()) |
|---|
| 15 | |
|---|
| 16 | (defclass c3 (c1) |
|---|
| 17 | ()) |
|---|
| 18 | |
|---|
| 19 | (defmethod g1 ((f c1)) 0) |
|---|
| 20 | |
|---|
| 21 | (defmethod g2 ((f c1)) 0) |
|---|
| 22 | (defmethod g2 ((b c2)) 0) |
|---|
| 23 | |
|---|
| 24 | (defvar *outer-times* 3) |
|---|
| 25 | (defvar *inner-times* 100000) |
|---|
| 26 | |
|---|
| 27 | (defmacro test (&body body) |
|---|
| 28 | `(let ((i1 (make-instance 'c1)) |
|---|
| 29 | (i2 (make-instance 'c2)) |
|---|
| 30 | (i3 (make-instance 'c3))) |
|---|
| 31 | (dotimes (i *outer-times*) |
|---|
| 32 | (time (dotimes (j *inner-times*) |
|---|
| 33 | ,@body))))) |
|---|
| 34 | |
|---|
| 35 | (defun fun-test () (test (fun i1))) |
|---|
| 36 | (defun accessor1-test () (test (accessor1 i1))) |
|---|
| 37 | (defun accessor2-test () (test (accessor2 i2) |
|---|
| 38 | (accessor2 i2))) |
|---|
| 39 | (defun accessor3-test () (test (accessor3 i1) |
|---|
| 40 | (accessor3 i2) |
|---|
| 41 | (accessor3 i3))) |
|---|
| 42 | (defun g1-test () (test (g1 i1))) |
|---|
| 43 | (defun g2-test () (test (g2 i2) |
|---|
| 44 | (g2 i2))) |
|---|
Note: See
TracBrowser
for help on using the repository browser.