Skip to content

Commit

Permalink
* Update optimizations and timings for README
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith James committed Aug 12, 2010
1 parent 7c043cf commit e69fd51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
16 changes: 8 additions & 8 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ RFC1952 is included, allowing a hybrid approach to reading gzip data,
using native Lisp streams and Zlib inflate/deflate.

Measuring execution times of the gz:gzip and gz:gunzip functions shows
deoxybyte-gzip to be fractionally slower than gzip/gunzip. The
Gray-streams implementation is up to 30% slower than gzip/gunzip.
deoxybyte-gzip to be fractionally slower than gzip, but over 3x slower
than gunzip.


Relative execution time (SBCL 1.0.32 X86-64):
Relative execution time (SBCL 1.0.40 X86-64):

gzip deoxybyte-gzip gzip-stream
Compression 1.0 1.05 1.11
Decompression 1.0 1.07 1.30
Compression 1.0 1.1 1.1
Decompression 1.0 3.1 3.5

Timings were taken compressing and decompressing a 1.4 Gb text file
Timings were taken compressing and decompressing a 1.8 Gb text file
using gzip/gunzip command line programs, the gz:gzip/gz:gunzip
functions (which use an internal buffer of length 2^16 -1) and the
Gray streams classes using
gz:stream-read-sequence/gz:stream-write-sequence methods.
gz:stream-read-sequence/gz:stream-write-sequence methods. A zlib
compression level of 6 was used.

This system is named with a deoxybyte- prefix because there are
several existing Common Lisp packages using the gzip name and I don't
Expand Down
12 changes: 8 additions & 4 deletions src/deoxybyte-gzip.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,16 @@ Key:
(defun gz-read (gz buffer n)
"Reads up to N bytes from GZ into octet vector BUFFER. Returns the
number of bytes read, which may be 0."
(declare (optimize (speed 3)))
(declare (type simple-octet-vector buffer))
(cond ((not (gz-open-p gz))
(gz-error gz nil "attempted to read from a closed stream"))
((gz-eof-p gz)
0)
(t
(with-foreign-pointer (buf (length buffer))
(let ((x (gzread (gz-ptr gz) buf n)))
(declare (type fixnum x))
(cond ((zerop x)
0)
((= -1 x)
Expand All @@ -200,14 +203,14 @@ number of bytes written. BUFFER must be a simple-array of
unsigned-byte 8."
(declare (optimize (speed 3)))
(declare (type simple-octet-vector buffer)
(type fixnum n))
(type vector-index n))
(unless (gz-open-p gz)
(gz-error gz nil "attempted to write to a closed stream"))
(with-foreign-pointer (buf (length buffer))
(loop
for i from 0 below n
do (setf (mem-aref buf :uint8 i) (aref buffer i)))
(let ((x (the fixnum (gzwrite (gz-ptr gz) buf n))))
(let ((x (gzwrite (gz-ptr gz) buf n)))
(if (zerop x)
(gz-error gz t t)
x))))
Expand Down Expand Up @@ -288,13 +291,14 @@ bytes decompressed."
"please specify OUT-FILESPEC explicitly.")
in-filespec)
(with-open-file (stream out-filespec :direction :output
:element-type 'octet :if-exists :supersede)
:element-type 'octet
:if-exists :overwrite :if-does-not-exist :create)
(with-gz-file (gz in-filespec)
(let ((x (1- (expt 2 16))))
(loop
with buffer = (make-array x :element-type 'octet
:initial-element 0)
for n = (gz-read gz buffer x)
for n of-type vector-index = (gz-read gz buffer x)
sum n into num-bytes
do (write-sequence buffer stream :end n)
until (gz-eof-p gz)
Expand Down
1 change: 1 addition & 0 deletions src/zlib-ffi.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
(defcfun ("gzclose" gzclose) :int
(gz :pointer))

(declaim (inline gzread))
(defcfun ("gzread" gzread) :int
(gz :pointer)
(buf :pointer)
Expand Down

0 comments on commit e69fd51

Please sign in to comment.