Comment Comment by gibsonf1 Unoptimzed version in Common Lisp (so has consing) (see performance against bible and bible x 10 later in this thread)For kjvbible.txt at (unoptimized) 0.365 is 3rd fastest beating C, and 4th faststest beating optimized Go(would be interesting to see how fast the optimized Lisp would be)Common Lisp (sbcl.org):(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)))))))) WEB> (time (performance-count "/home/frederick/performance-comparison.txt"))the 4foo 2defenestration 1 parent gibsonf1 5 years ago
For kjvbible.txt at (unoptimized) 0.365 is 3rd fastest beating C, and 4th faststest beating optimized Go
(would be interesting to see how fast the optimized Lisp would be)
Common Lisp (sbcl.org):
(defmethod performance-count ((path-file string))
WEB> (time (performance-count "/home/frederick/performance-comparison.txt"))the 4
foo 2
defenestration 1