From: Slobodan Blazeski
Subject: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <30bcd777-ef3c-4cb9-8f38-0519af511c8d@v46g2000hsv.googlegroups.com>
Why isn't scanner created in the let form at compile time , instead of
recreating it for each call of email-let-fix?  http://paste.lisp.org/display/53728
(defvar *email*  ··················@gmail.com")

(defun email-let-fix (email)
  (let ((scanner (cl-ppcre:create-scanner
··················@gmail.com")))
    (cl-ppcre:scan scanner email)))
EMAIL-LET-FIX

(defvar *scanner*  (create-scanner *email*))
*SCANNER*

(defun email-pre-scanner (email)
  (declare (special *email*))
    (cl-ppcre:scan *scanner* email))
EMAIL-PRE-SCANNER

(defun test (n fn arg)
  (dotimes (i n)
    (funcall fn arg)))
TEST

(mapcar #'compile '(test email-let-fix email-pre-scanner))
(TEST EMAIL-LET-FIX EMAIL-PRE-SCANNER)

(mapcar #'compiled-function-p (list #'test #'email-let-fix #'email-pre-
scanner))
(T T T)

(time (test 10000 #'email-pre-scanner *email*))
Timing the evaluation of (TEST 10000 (FUNCTION EMAIL-PRE-SCANNER)
*EMAIL*)

User time    =        0.020
System time  =        0.000
Elapsed time =        0.020
Allocation   = 0 bytes
0 Page faults
NIL

(time (test 10000 #'email-let-fix *email*))
Timing the evaluation of (TEST 10000 (FUNCTION EMAIL-LET-FIX) *EMAIL*)

User time    =       20.629
System time  =        0.030
Elapsed time =       21.551
Allocation   = 5276074020 bytes
0 Page faults
NIL

cheers
Slobodan

From: Edi Weitz
Subject: Re: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <uy7b24iu7.fsf@agharta.de>
On Sun, 6 Jan 2008 15:38:27 -0800 (PST), Slobodan Blazeski <·················@gmail.com> wrote:

> Why isn't scanner created in the let form at compile time

Why should it?

-- 

European Common Lisp Meeting, Amsterdam, April 19/20, 2008

  http://weitz.de/eclm2008/

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: John Thingstad
Subject: Re: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <op.t4i8kiphut4oq5@pandora.alfanett.no>
P� Mon, 07 Jan 2008 00:38:27 +0100, skrev Slobodan Blazeski  
<·················@gmail.com>:

> Why isn't scanner created in the let form at compile time , instead of
> recreating it for each call of email-let-fix?   
> http://paste.lisp.org/display/53728
> (defvar *email*  ··················@gmail.com")
>
> (defun email-let-fix (email)
>   (let ((scanner (cl-ppcre:create-scanner
> ··················@gmail.com")))
>     (cl-ppcre:scan scanner email)))
> EMAIL-LET-FIX
>

Because you create one each time you call the function.
Always move the creation of the scanner outside the loop if it doesn't  
change.
(It doesn't have to be special)

--------------
John Thingstad
From: Slobodan Blazeski
Subject: Re: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <2c17a4f6-da37-4da8-8546-1f878be6f2af@t1g2000pra.googlegroups.com>
Stupid me, I should have coded the clozure as:
(let ((scanner (cl-ppcre:create-scanner
··················@gmail.com")))
  (defun email-let-fix (email)
    (cl-ppcre:scan scanner email)))
EMAIL-LET-FIX

now everything is great.

(time (test 10000 #'email-let-fix *email*))
Timing the evaluation of (TEST 10000 (FUNCTION EMAIL-LET-FIX) *EMAIL*)

User time    =        0.160
System time  =        0.000
Elapsed time =        0.511
Allocation   = 3445392 bytes
0 Page faults
Calls to %EVAL    30034
NIL

cheers
Slobodan
From: Edi Weitz
Subject: Re: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <umyri1lgy.fsf@agharta.de>
On Sun, 6 Jan 2008 16:02:42 -0800 (PST), Slobodan Blazeski <·················@gmail.com> wrote:

> Stupid me, I should have coded the clozure as:
> (let ((scanner (cl-ppcre:create-scanner ··················@gmail.com")))
>   (defun email-let-fix (email)
>     (cl-ppcre:scan scanner email)))
> EMAIL-LET-FIX

This

  (defun email-let-fix (email)
    (ppcre:scan ··················@gmail.com" email))

should have the same effect if the function is compiled.  See the
compiler macros in api.lisp.

Edi.

-- 

European Common Lisp Meeting, Amsterdam, April 19/20, 2008

  http://weitz.de/eclm2008/

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Slobodan Blazeski
Subject: Re: Compile time creation of cl-ppcre scanner in let
Date: 
Message-ID: <dc38b7fa-f5b3-448f-9eae-2141861bdeda@i7g2000prf.googlegroups.com>
On Jan 7, 2:19 am, Edi Weitz <········@agharta.de> wrote:
> On Sun, 6 Jan 2008 16:02:42 -0800 (PST), Slobodan Blazeski <·················@gmail.com> wrote:
> > Stupid me, I should have coded the clozure as:
> > (let ((scanner (cl-ppcre:create-scanner ··················@gmail.com")))
> >   (defun email-let-fix (email)
> >     (cl-ppcre:scan scanner email)))
> > EMAIL-LET-FIX
>
> This
>
>   (defun email-let-fix (email)
>     (ppcre:scan ··················@gmail.com" email))
>
> should have the same effect if the function is compiled.  See the
> compiler macros in api.lisp.
>

I decided to defparameter the scanner so the user could easily change
it's own regex if it doesn't like mine.

Thanks for your advice.

cheers
Slobodan
> Edi.
>
> --
>
> European Common Lisp Meeting, Amsterdam, April 19/20, 2008
>
>  http://weitz.de/eclm2008/
>
> Real email: (replace (subseq ·········@agharta.de" 5) "edi")