Created
May 13, 2014 20:39
-
-
Save jdz/39febf2a1f50c7f0b119 to your computer and use it in GitHub Desktop.
Silly program in dynamic language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; The Ubuntu image file is 564MB, the largest file close to 1G I could | |
;;; quickly find. | |
(defun process (&optional (file #p"~/Downloads/ubuntu-14.04-server-amd64.iso")) | |
(declare (optimize (speed 3) (safety 1))) | |
(with-open-file (in file :direction :input | |
:element-type 'unsigned-byte) | |
(let ((buf (make-array #xffff :element-type '(unsigned-byte 8))) | |
(result 0)) | |
(loop for read = (read-sequence buf in) | |
until (zerop read) | |
do (loop for x across buf | |
do (setf result | |
(ldb (byte 8 0) (+ result x))))) | |
result))) | |
#| | |
CL-USER> (time (process)) | |
Evaluation took: | |
0.658 seconds of real time | |
0.659847 seconds of total run time (0.502664 user, 0.157183 system) | |
100.30% CPU | |
1,509,934,829 processor cycles | |
27,936 bytes consed | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not that I had to get out of my way to make the result be just one byte, not the actual sum of bytes.