3 ms·
(defun get-longest-path (nodes node-id visited) (declare (optimize (speed 3) (space 0) (debug 0) (safety 0) (compilation-speed 0)
by lispm 12y ago
(defun get-longest-path (nodes node-id visited)
(declare (optimize (speed 3) (space 0) (debug 0) (safety 0)
(compilation-speed 0)
#+lispworks (fixnum-safety 0))
(type fixnum node-id)
(type (vector node) nodes)
(type (vector atom) visited))
(setf (aref visited node-id) t)
(Let ((max (loop for neighbour of-type route across (node-neighbours (aref nodes node-id))
unless (aref visited (route-dest neighbour))
maximize (the fixnum
(+ (the fixnum (route-cost neighbour))
(the fixnum (get-longest-path nodes (route-dest neighbour) visited)))))))
(declare (fixnum max))
(setf (aref visited node-id) nil)
max))
Above Common Lisp version improves the runtime from 8.5 to 3.6 seconds in SBCL and from 30 seconds to 2 seconds in LispWorks 64bit. Computer: i7 Mac mini.
- logicchains 12y agoNice, re-running the benchmark with the new code now. *Edit: and, it's done.
- lispm 12y agohere is a much faster version: https://gist.github.com/lispm/6066e1eeadf943910c47 https://gist.github.com/lispm/6066e1eeadf943910c47 You might want to adapt it...
- logicchains 12y agoI'm off to bed now, I'll pull it in the morning.
- lispm 12y agoI've created a version with some explanations about performance issues... https://gist.github.com/lispm/e9372894519f8e6feae1 https://gist.github.com/lispm/e9372894519f8e6feae1