2 ms·
What code was used for Common Lisp? I'm guessing a well written version would be in the top contenders for speed.
by gibsonf1 4y ago
What code was used for Common Lisp? I'm guessing a well written version would be in the top contenders for speed.
- Jtsummers 4y agohttps://github.com/benhoyt/countwords/blob/master/simple.lisp https://github.com/benhoyt/countwords/blob/master/simple.lis... From Hoyt's repository itself.
- gibsonf1 4y agoWhich lisp compiler did you use?
- Jtsummers 4y agoI haven't run it, just tracked down the source because I was similarly curious about the slow runtime. If I do run it it will be with SBCL. Looking at the repo, Hoyt did as well.
- gibsonf1 4y agoThat code is slow because it's working with a really long list instead of a very fast hash table
- gibsonf1 4y agoRight, this came up a year ago with a version that ranks among the top here: https://news.ycombinator.com/item?id=26465857 https://news.ycombinator.com/item?id=26465857 (defmethod performance-count ((path-file string)) (let ((map (make-hash-table :test 'equal))) (with-open-file (stream path-file :direction :input :if-does-not-exist nil) (when stream (loop for line = (read-line stream nil 'end) until (eq line 'end) do (let ((split (split-string #\space (string-downcase line)))) (dolist (word split) (let ((index (gethash word map))) (if index (setf (gethash word map) (incf index)) (setf (gethash word map) 1)))))) (let ((keys (sort (alexandria:hash-table-keys map) (lambda(x y)(> (gethash x map)(gethash y map)))))) (dolist (key keys) (format t "~A ~A~%" key (gethash key map))))))))