[Openmcl-devel] pattern matching

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Wed Dec 8 09:54:17 UTC 2010


Hi

I run the following test to have a first idea about with-match-destruc
performance


? (time (dotimes (i 1000000) (with-match-destruc (a (s x) d) '(a (s 42)
d))))
;Compiler warnings :
;   In an anonymous lambda form: Unused lexical variable D
;   In an anonymous lambda form: Unused lexical variable #:G2479
;   In an anonymous lambda form: Unused lexical variable X
;   In an anonymous lambda form: Unused lexical variable #:G2482
;   In an anonymous lambda form: Unused lexical variable S
;   In an anonymous lambda form: Unused lexical variable A
(DOTIMES (I 1000000) (WITH-MATCH-DESTRUC (A (S X) D) '(A (S 42) D))) took 33
milliseconds (0.033 seconds) to run
                    with 2 available CPU cores.
During that period, 33 milliseconds (0.033 seconds) were spent in user mode
                    0 milliseconds (0.000 seconds) were spent in system mode
NIL
? (time (dotimes (i 1000000) (unify::unify '(a (s 42) d) '(a (s 42) d))))
(DOTIMES (I 1000000) (IT.UNIMIB.DISCO.MA.CL.EXT.DACF.UNIFICATION:UNIFY '(A
(S 42) D) '(A (S 42) D))) took 3,365 milliseconds (3.365 seconds) to run
                    with 2 available CPU cores.
During that period, 3,303 milliseconds (3.303 seconds) were spent in user
mode
                    38 milliseconds (0.038 seconds) were spent in system
mode
76 milliseconds (0.076 seconds) was spent in GC.
 40,000,000 bytes of memory allocated.
NIL
? (let ((sum 0))
(time (dotimes (i 1000000) (with-match-destruc (a (s x) d) '(a (s 42) d)
(incf sum x))))
sum)
;Compiler warnings :
;   In an anonymous lambda form inside an anonymous lambda form: Unused
lexical variable A
;   In an anonymous lambda form inside an anonymous lambda form: Unused
lexical variable S
;   In an anonymous lambda form inside an anonymous lambda form: Unused
lexical variable #:G2502
;   In an anonymous lambda form inside an anonymous lambda form: Unused
lexical variable #:G2499
;   In an anonymous lambda form inside an anonymous lambda form: Unused
lexical variable D
(DOTIMES (I 1000000) (WITH-MATCH-DESTRUC (A (S X) D) '(A (S 42) D) (INCF SUM
X))) took 36 milliseconds (0.036 seconds) to run
                    with 2 available CPU cores.
During that period, 36 milliseconds (0.036 seconds) were spent in user mode
                    0 milliseconds (0.000 seconds) were spent in system mode
42000000


Kind regards
Taoufik

On Mon, Dec 6, 2010 at 11:38 PM, Daniel Weinreb <dlw at itasoftware.com> wrote:

>  Greg,
>
> This may be of no importance, but: unification is
> a very powerful mechanism.  If one is using
> cl-unification to do simple things like
> what defmacro does, is it reasonably fast?
>
> -- Dan
>
> Greg Pfeil wrote:
>
> On 4 Dec 2010, at 8:02, Taoufik Dachraoui wrote:
>
>
>
>  Hello
>
> I wrote a matching pattern function and would like to share in order
> to improve it (remove the compiler warnings for example, see below).
>
> I started with the destruc function found in onLisp book by Paul Graham.
>
>
>  I don't recall if it has any type restrictions, but I tend to use CL Unification (http://common-lisp.net/project/cl-unification/) for pattern matching stuff.
>
>
>
>  Any matching symbol x can be typed  and must be of the form (:type x #'name)
> where name is a boolean function with one argument (eg. numberp, consp, symbolp,
> atom, ...)
>
>
>  Why not have the form be (:type var typename), like (:type x '(integer 0 9))? Then you get much finer control without having to define unary functions for every type you care about. Should be able to just replace (funcall ,(third pat) (car ,seq)) with (typep (car ,seq) ,(third pat)) and you're golden.
> _______________________________________________
> Openmcl-devel mailing listOpenmcl-devel at clozure.comhttp://clozure.com/mailman/listinfo/openmcl-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20101208/1dbd20d1/attachment.html>


More information about the Openmcl-devel mailing list