I was profiling the following expression
(cl-ppcre::scan "(\S+)\s*(.*)" "DE Halobacterium halobium ribosomal proteins, partial and complete")
and char=, char/= and char<= were coming up highest in the breakdown.
One way to conservatively fix (least number of edits to the source) would be the following, which gets about a factor of 2x for the above expression. Arguably, this might be considered for inclusion in openmcl proper.
Similar could be done for char-equal etc.
-Alan
#+openmcl (define-compiler-macro char<= (&whole form &environment env char &rest others) "" (if (and (= (ccl::speed-optimize-quantity env) 3) (= (ccl::safety-optimize-quantity env) 0)) (cond ((= (length others) 1) `(ccl::%i<= (the fixnum (char-code (the character ,char))) (the fixnum (char-code (the character ,(car others)))))) ((= (length others) 2) `(let ((middle (char-code (the character ,(car others))))) (declare (fixnum middle)) (and (ccl::%i<= (the fixnum (char-code (the character ,char))) middle) (ccl::%i<= middle (the fixnum (char-code (the character ,(second others)))))))) (t form)) form))
#+openmcl (define-compiler-macro char= (&whole form &environment env char &rest others) "" (if (and (= (ccl::speed-optimize-quantity env) 3) (= (ccl::safety-optimize-quantity env) 0)) (cond ((= (length others) 1) `(eq ,char ,(car others))) (t form)) form))
#+openmcl (define-compiler-macro char/= (&whole form &environment env char &rest others) "" (if (and (= (ccl::speed-optimize-quantity env) 3) (= (ccl::safety-optimize-quantity env) 0)) (cond ((= (length others) 1) `(not (eq ,char ,(car others)))) (t form)) form))
;; add the optimize declares in the lambdas below so the compiler optimization kicks in.
(defmethod create-matcher-aux ((char-class char-class) next-fn) (declare (type function next-fn)) ;; insert a test against the current character within *STRING* (insert-char-class-tester (char-class (schar *string* start-pos)) (if (invertedp char-class) (lambda (start-pos) (declare (type fixnum start-pos)) (declare (optimize (speed 3) (safety 0))) (and (< start-pos *end-pos*) (not (char-class-test)) (funcall next-fn (1+ start-pos)))) (lambda (start-pos) (declare (type fixnum start-pos)) (declare (optimize (speed 3) (safety 0))) (and (< start-pos *end-pos*) (char-class-test) (funcall next-fn (1+ start-pos)))))))
Actually, closer to a 3x speedup.
(DOTIMES (I 1000000) (CL-PPCRE:SCAN "(\S+)\s*(.*)" "DE Halobacterium halobium ribosomal proteins, partial and complete")) took 14,655 milliseconds (14.655 seconds) to run.
vs.
(DOTIMES (I 1000000) (CL-PPCRE:SCAN "(\S+)\s*(.*)" "DE Halobacterium halobium ribosomal proteins, partial and complete")) took 4,989 milliseconds (4.989 seconds) to run.
-Alan
On Dec 15, 2004, at 1:13 AM, Alan Ruttenberg wrote:
I was profiling the following expression
(cl-ppcre::scan "(\S+)\s*(.*)" "DE Halobacterium halobium ribosomal proteins, partial and complete")
and char=, char/= and char<= were coming up highest in the breakdown.
One way to conservatively fix (least number of edits to the source) would be the following, which gets about a factor of 2x for the above expression. Arguably, this might be considered for inclusion in openmcl proper.
Similar could be done for char-equal etc.
Hi Alan!
On Wed, 15 Dec 2004 01:13:56 -0500, Alan Ruttenberg alanr-l@mumble.net wrote:
I was profiling the following expression
(cl-ppcre::scan "(\S+)\s*(.*)" "DE Halobacterium halobium ribosomal proteins, partial and complete")
and char=, char/= and char<= were coming up highest in the breakdown.
One way to conservatively fix (least number of edits to the source) would be the following, which gets about a factor of 2x for the above expression. Arguably, this might be considered for inclusion in openmcl proper.
Similar could be done for char-equal etc.
That's an impressive speedup for such a few lines of code but I agree with you that this should be actually included into OpenMCL. I hesitate to add stuff to CL-PPCRE that's so specific to one implementation.
Thanks, Edi.
cl-ppcre-devel@common-lisp.net