|
Prev: static typing
Next: Java is going to have closures.
From: verec on 12 Aug 2006 18:38 On 2006-08-12 21:27:36 +0100, Wade Humeniuk <whumeniu+anti+spam(a)telus.net> said: > Removed some expt stuff, I think it is still correct. Hmmm. That's a point I overlooked when copying and pasting your example (as well as PK's.) The thing is, both of your version are about 10 times faster than what I intially came up with _precisely_ because you have replaced (expt x 2) with (* x x) When I plug (expt x 2) back into the loop, I get again the same dismall performance as with my initial version. with: do (incf sum (* 2d0 (exp (- (* x x))))) 12s with: do (incf sum (* 2d0 (exp (- (expt x 2.0d0))))) 115s! but with: do (incf sum (* 2d0 (exp (- (realpart (expt x 2.0d0)))))) 88s Hmmm. Still scratching my head :-( -- JFB
From: verec on 12 Aug 2006 18:53 On 2006-08-12 23:28:59 +0100, Glenn.Ehrlich(a)specastro.com said: > Here are some good links on improving numerical computation speed in > Common Lisp: > > "On using Common Lisp in scientific computing", by Nicolas Neuss. This > has a pretty good tuturial-level introduction to how to do numerical > optimization in Common Lisp. > http://www.iwr.uni-heidelberg.de/organization/sfb359/PP/Preprint2002-40.ps.gz > > "Fast Floating-Point Processing in Common Lisp", by Richard Fateman. > This is a more in-depth treatment. > http://www.cs.berkeley.edu/~fateman/papers/lispfloat.ps > > Ken Anderson's Common Lisp Performance page: > http://openmap.bbn.com/~kanderso/performance/ > > Additionally, here's a listing of math oriented libraries available for > Common Lisp: > http://www.cliki.net/mathematics Much appreciated. Thanks! > Glenn -- JFB
From: Pascal Bourguignon on 12 Aug 2006 19:08 verec <verec(a)mac.com> writes: > On 2006-08-12 21:27:36 +0100, Wade Humeniuk > <whumeniu+anti+spam(a)telus.net> said: > >> Removed some expt stuff, I think it is still correct. > > Hmmm. That's a point I overlooked when copying and pasting > your example (as well as PK's.) > > The thing is, both of your version are about 10 times > faster than what I intially came up with _precisely_ > because you have replaced (expt x 2) with (* x x) > > When I plug (expt x 2) back into the loop, I get again > the same dismall performance as with my initial version. You can write a compiler-macro. Unfortunately, not on CL:EXPT since this is forbidden, but you can do it this way: (shadow 'expt) (declaim (inline expt)) (defun expt (base-number power-number) (cl:expt base-number power-number)) (define-compiler-macro expt (&whole whole base-number power-number) (if (equal 2 power-number) (let ((bn (gensym))) `(let ((,bn ,base-number)) (* ,bn ,bn))) whole)) Then compare: (disassemble (compile (defun f (x) (expt x 2)))) (disassemble (compile (defun g (x y) (expt x y)))) So there is no need in modifying the source, keep (expt x 2). (You can also write a more sophisticated compiler macro, handing other constant exponents). -- __Pascal Bourguignon__ http://www.informatimago.com/ "This statement is false." In Lisp: (defun Q () (eq nil (Q)))
From: verec on 12 Aug 2006 19:27 On 2006-08-13 00:08:25 +0100, Pascal Bourguignon <pjb(a)informatimago.com> said: > You can write a compiler-macro. Unfortunately, not on CL:EXPT since > this is forbidden, but you can do it this way: > > (shadow 'expt) > (declaim (inline expt)) > (defun expt (base-number power-number) (cl:expt base-number power-number)) > (define-compiler-macro expt (&whole whole base-number power-number) > (if (equal 2 power-number) > (let ((bn (gensym))) > `(let ((,bn ,base-number)) (* ,bn ,bn))) > whole)) > > Then compare: > > (disassemble (compile (defun f (x) (expt x 2)))) > (disassemble (compile (defun g (x y) (expt x y)))) Cute :-) Many thanks -- JFB
From: Lars Brinkhoff on 13 Aug 2006 07:50
verec <verec(a)mac.com> writes: > I have been challenged to "port" to CL the following (for now > quite inaccurate) approximation of pi/2. Depending on the > speed outcome, CL may get considered for the project that > will be havy on mumeric computations. I get consistently *faster* run times with SBCL 0.9.14.30 than with GCC 4.0.4 using plain C, not C++. (There's no reason C++ would be faster, is there?) 100,000 iterations on a 2GHz x86: SBCL 17.729 seconds of real time 17.713108 seconds of user run time 0.004 seconds of system run time 0 page faults and 0 bytes consed. GCC real 0m19.948s user 0m19.861s sys 0m0.004s |