[Openmcl-devel] tagbody and go

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Wed Dec 8 11:03:22 PST 2010


Hi

I think I found the best way to do it, by using a macro and vector of
conses:

(defvar *y* (make-array 100 :element-type 'cons))

(defmacro m1 (a) `,(svref *y* a))

(setf (svref *y* 20) '(+ x 1))

? (time (dotimes (i 10000000) (let ((x 3)) (m1 20))))
(DOTIMES (I 10000000) (LET ((X 3)) (M1 20))) took 31 milliseconds (0.031
seconds) to run
                    with 2 available CPU cores.
During that period, 31 milliseconds (0.031 seconds) were spent in user mode
                    1 milliseconds (0.001 seconds) were spent in system mode
NIL
?

The timing is the same as with tagbody/go

The other solution is to do with a vector of functions but it is 3 times
slower but faster than ecase:

(defvar *x* (make-array 100 :element-type 'function))

(setf (svref *x* 20) #'(lambda (x) (+ x 1)))

? (time (dotimes (i 10000000) (let ((x 3)) (funcall (svref *x* 20) x))))
(DOTIMES (I 10000000) (LET ((X 3)) (FUNCALL (SVREF *X* 20) X))) took 118
milliseconds (0.118 seconds) to run
                    with 2 available CPU cores.
During that period, 118 milliseconds (0.118 seconds) were spent in user mode
                    0 milliseconds (0.000 seconds) were spent in system mode
NIL
?


Kind regards
Taoufik


On Wed, Dec 8, 2010 at 7:15 PM, Julian Squires <julian at cipht.net> wrote:

> On Wed, Dec 8, 2010 at 11:52 AM, Taoufik Dachraoui
> <dachraoui.taoufik at gmail.com> wrote:
> > The ecase will check all the clauses in order (like cond) until it finds
> a
> > match.
>
> Not necessarily.  See Geoff Wozniak's comparison of case performance
> on his blog:
>
> http://exploring-lisp.blogspot.com/2009/07/postscript-to-jump-tables-stuff.html
> (that post has his conclusions and links to the earlier posts which
> contain performance figures, as well as macros which might do what you
> want.)
>
> --
> Julian Squires
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20101208/e7d097ab/attachment.htm>


More information about the Openmcl-devel mailing list