[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: I/O efficiency question
> Date: Tue, 23 Feb 1993 08:46:50 -0800
> From: Peter Shell <pshell@nl.cs.cmu.edu>
>
> By calling EXCL::STM-FILE-BUFFERED-READ-CHAR and
> EXCL::STM-FILE-BUFFERED-WRITE-CHAR directly I was able to bypass
> the method stuff, speeding up my program considerably (45%).
If you really want to make your program burn, try the following:
(defmacro fast-read-char (stream)
#+(and allegro (version>= 4)) `(stream:stream-read-char ,stream)
#+lucid`(lcl:fast-read-char ,stream nil :eof)
#-(or (and allegro (version>= 4)) lucid) `(read-char ,stream nil :eof))
(defmacro fast-read-file-char (stream) `(fast-read-char ,stream))
#+(and allegro (version>= 4))
(define-compiler-macro fast-read-file-char (stream)
`(macrolet ((stream-slots (stream)
`(the simple-vector (svref ,stream 1)))
(stream-buffer (slots)
`(the simple-string (svref ,slots 11)))
(stream-buffpos (slots)
`(the fixnum (svref ,slots 12)))
(stream-maxbuffpos (slots)
`(the fixnum (svref ,slots 13))))
(declare (optimize (speed 3) (safety 0)))
(let* ((stream ,stream)
(slots (stream-slots stream))
(buffpos (stream-buffpos slots))
(maxbuffpos (stream-maxbuffpos slots)))
(declare (fixnum buffpos maxbuffpos))
(if (>= buffpos maxbuffpos)
(stream:stream-read-char stream)
(prog1 (schar (stream-buffer slots) buffpos)
(when (= (setf (stream-buffpos slots) (the fixnum (1+ buffpos)))
maxbuffpos)
(setf (stream-maxbuffpos slots) 0)))))))