Skip to content

Instantly share code, notes, and snippets.

@takagi
Created March 26, 2015 11:51
Show Gist options
  • Save takagi/0592581f53205fcab529 to your computer and use it in GitHub Desktop.
Save takagi/0592581f53205fcab529 to your computer and use it in GitHub Desktop.
Comparing efficiency of READ-BYTE with READ-SEQUENCE.
(require :sb-sprof)
(defun test-read-byte0 ()
(with-open-file (in "data" :direction :input
:element-type '(unsigned-byte 8))
(loop repeat (* 4 1024 1024)
do (read-byte in))))
(defun profile-read-byte0 ()
(sb-sprof:with-profiling (:max-samples 100
:report :graph
:loop t)
(test-read-byte0)))
(defun test-read-byte ()
(with-open-file (out "/dev/null" :direction :output
:if-exists :supersede
:element-type '(unsigned-byte 8))
(with-open-file (in "data" :direction :input
:element-type '(unsigned-byte 8))
(loop repeat (* 4 1024 1024)
do (write-byte (read-byte in) out)))))
(defun profile-read-byte ()
(sb-sprof:with-profiling (:max-samples 100
:report :graph
:loop t)
(test-read-byte)))
(defun test-read-sequence ()
(with-open-file (out "/dev/null" :direction :output
:if-exists :supersede
:element-type '(unsigned-byte 8))
(with-open-file (in "data" :direction :input
:element-type '(unsigned-byte 8))
(let ((buf (make-array 1024 :element-type '(unsigned-byte 8))))
(loop repeat (* 4 1024)
do (read-sequence buf in :end 1024)
(write-sequence buf out :end 1024)))))
nil)
(defun profile-read-sequence ()
(sb-sprof:with-profiling (:max-samples 100
:report :graph
:loop t)
(test-read-sequence)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment