Re: STk I/O Performance

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Tue, 18 Apr 1995 11:16:55 +0100

> Andrew Joseph Kompanek writes
>
> When I open a 34 K file and read characters, I get the following
> performance (this is on an HP 9007s715):
>
> (time (let ((ch (read-char port)))
> (while (not (eof-object? ch)) (set! ch (read-char port)))))
>
> ;; Time: 1520.00ms
> ;; GC time: 110.00ms
> ;; Cells: 68082
>
>
> This is about 22K/second. A C program that uses fopen and getc on
> the same machine gives about 2Mb/second.
>
> Is a 100 time slow-down to be expected? Is there any way to speed
> this up by changing buffering, etc?
>
The problem seems to have several causes and makes things hard to find where
time is exactly consumed.

There must be some control which must be done each time a character is read
(i.e. see if port is a port file and verify that the port is opened for
reading). Of course, this calls must be done for each character even if port
doesn't change between each call. Furthermore, the read-char primitive calls a
low level function of the interpreter which takes into account string ports
and Control-C interrupts....
I have tried to replace the standard read-char by a new primitive which makes
no test at all (!!). This primitive was simply:
        PRIMITIVE fast_read_char(SCM port)
        {
          int c;

          c = fgetc(port->storage_as.port.f);
          return (c == EOF) ? STk_eof_object : STk_makechar(c);
        }
I was surprised to sse that the gain was very small (from 25Kb/s to 28Kb/s).
Consequently, I have tried to see how to optimize further the reading of this
file.

On the other side replacing read-char by read (original file was a 50Kb Scheme
program). Read plays here the role of a tokenizer written in C. With read, the
obtained rate was 136Kb/s.

Since this "program" only contains read-char and a while, I have tried to see
the influence of the language used for writing the control loop.
Using your program with a while written in C rather than in Scheme gives a
reading rateof 48Kb/s, which is nearly two time faster than the initial loop.

Using an unless (rather than a "while not") written in C yields a 53Kb reading
rating.

Using an unless written in C and red (the tokenizer written in C) permits to
read 149Kb/s (i.e. nearly six time faster than original version).

Conclusion: It seems to be possible to speed up your program by at least a
factor of 4 or 5 (if your test program is representative of your application)
by
        1. writing while and unless in C. This is my job (which is done now :-)
        2. writing your tokenizer or (parts of it in C)

Hope it helps



                -- Erick
Received on Tue Apr 18 1995 - 11:16:56 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST