@simon_brooke @vashti Only if it doesn’t also need to be fast.
Discussion
@simon_brooke @vashti Only if it doesn’t also need to be fast.
@alwayscurious @vashti define fast. I can compute the factorial of 1,000 in under one millisecond on an ordinary laptop in several different #Lisp dialects, without optimisation.
Is that not fast enough for you?
https://gist.github.com/simon-brooke/fcb59705950c5ad515e18fba065510ae
Agreed. #CommonLisp on Android ( #cl_repl) is capable and plenty fast enough on a Pixel 8a running your factorial code. 😎
You can make CL faster than the C/C++ used by NumPy: https://stewart123579.github.io/blog/posts/code/calculating-a-dot-product/#python-vs-dot-r-vs-dot-lisp-timing
@svw @alwayscurious @vashti from the cons space usage I'm guessing that was the recursive algorithm? If so, the more impressive. Small #Lisp imlementations tend not to have dynamic stack. But allocating and deallocating stack frames on a dynamic stack is a time cost.
@svw
Sorry, could you time the
(mytime naïve-dot-v2 "naïve loop v2"
(loop for x across aa
for y across ab
summing (* x y)))
idiom instead?
Thinking about it, I'm not sure how to write DO for this. I have been interested in DO recently.
@simon_brooke @alwayscurious @vashti
@screwlisp Right, what arguments do you want me to test?
@simon_brooke could you do something comparable to svw. but with
(loop for x fixnum across arrayx for y fixnum across arrayy summing (* x y) into z fixnum finally (return z))
and
(do ((x (pop listx) (pop listx)) (y (pop listy) (pop listy)) (z 0))
((null listx) (incf z (* x y)))
(declare (fixnum x y z))
(incf z (* x y)))
which are my swing at fast forms closely analogous to svw's fast lisp blogging. I'm also interested in how similar performance gains and losses are between lisps.
@screwlisp aye, but arguments! What arguments to these functions would it be useful to you for me to test?
@svw
Though, based on my laptop,
(defun doot2 (a b)
(do ((z 0)
(x (pop a) (pop a))
(y (pop b) (pop b)))
((null a) (incf z (* x y)))
(declare (fixnum x y z))
(incf z (* x y))))
consistently beats
(defun loopdot (a b)
(loop :for x fixnum :in a
:for y fixnum :in b
:summing (* x y) :into z fixnum
:finally (return z)))
@simon_brooke @alwayscurious @vashti
@alwayscurious @vashti however, I'm grateful to you for raising that issue, because it prompted me to find out how fast it would run in Portable Standard #Lisp, so I've spent a happy couple of hours trying to debug bootstrapping problems in Blake McBride's version of the PSL compiler. I don't have it working yet, but I have made progress. Will it be faster than SBCL? Don't know, but I suspect so.
BT Free is a non-profit organization founded by @ozoned@btfree.social . It's goal is for digital privacy rights, advocacy and consulting. This goal will be attained by hosting open platforms to allow others to seamlessly join the Fediverse on moderated instances or by helping others join the Fediverse.