Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    (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.


I've created a version with some explanations about performance issues...

https://gist.github.com/lispm/e9372894519f8e6feae1


Nice, re-running the benchmark with the new code now.

*Edit: and, it's done.


here is a much faster version:

https://gist.github.com/lispm/6066e1eeadf943910c47

You might want to adapt it...


I'm off to bed now, I'll pull it in the morning.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: