SV: Re: Referencing a row in a two dimensional array
"Pavel Grozman" <[email protected]>
| Newsgroups | gmane.lisp.corman |
|---|---|
| Message-ID | <[email protected]> |
>
> However the time delta between a single call to READ-SEQUENCE and my
> previous loop which called READ-BYTE for each byte read is
> negligable. In CLL, READ-SEQUENCE seems to be implemented as a loop
> calling READ-BYTE.
>
> I was hoping that READ-SEQUENCE actually read an entire block of
> bytes in one shot, similar to "fread" in C, as this would probably
> increase performance (in my case) by a factor of 100 or more.
>
Corman Lisp cannot read from file directly to Lisp data because
blocks of Lisp data may be moved by garbage collector.
Corman Lisp first reads to a "foreign block", than copies this block
to file buffer, and read-byte reads from buffer to the target data.
So it is hardly possible to increase performance by a factor of 100.
Here is a function that reads the block 3 times faster:
(defun read-bytes (vector stream &optional (start 0) end)
(let (length buf buf-pos buf-end)
(multiple-value-setq (length end) (cl::validate-bounding-indices
vector start end))
(unless (and (cl::binary-stream-p stream)(input-stream-p stream))
(error "Expected a binary input stream, got ~A" stream))
(setq buf (cl::stream-input-buffer stream))
(do ((p start))
(nil)
(setf buf-pos (cl::stream-input-buffer-pos stream)
buf-end (cl::stream-input-buffer-num stream))
(when (= buf-pos buf-end)
(funcall (cl::stream-underflow-function stream) stream)
(setf buf-pos (cl::stream-input-buffer-pos stream)
buf-end (cl::stream-input-buffer-num stream))
(when (= buf-pos buf-end)
(return-from read-bytes p)))
(do ((i buf-pos (+ i 1)))
((= i buf-end) (setf (cl::stream-input-buffer-pos stream)
buf-end))
(when (= p end)
(setf (cl::stream-input-buffer-pos stream) i)
(return-from read-bytes end))
(setf (elt vector p) (elt buf i))
(incf p)))))
By redefining function elt I can read blocks 5 time faster.
I am planning also to write functions for fast copying data;
they may be used both to copy from "foreign buffer" to stream buffer
and from stream buffer to target data (if no data conversion required).
Pavel Grozman
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/LIgTpC/vN2EAA/xGHJAA/SyjtlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/