Browse files

* Update optimizations and timings for README

  • Loading branch information...
1 parent 7c043cf commit e69fd513df05c296bea617524aefb9d6745c5015 @keithj committed Aug 12, 2010
Showing with 17 additions and 12 deletions.
  1. +8 −8 README.txt
  2. +8 −4 src/deoxybyte-gzip.lisp
  3. +1 −0 src/zlib-ffi.lisp
@@ -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
@@ -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)
(with-foreign-pointer (buf (length buffer))
(let ((x (gzread (gz-ptr gz) buf n)))
+ (declare (type fixnum x))
(cond ((zerop x)
((= -1 x)
@@ -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))
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)
@@ -288,13 +291,14 @@ bytes decompressed."
"please specify OUT-FILESPEC explicitly.")
(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))))
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)
@@ -211,6 +211,7 @@
(defcfun ("gzclose" gzclose) :int
(gz :pointer))
+(declaim (inline gzread))
(defcfun ("gzread" gzread) :int
(gz :pointer)
(buf :pointer)

0 comments on commit e69fd51

Please sign in to comment.