[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why is READ-CHAR so blindingly slow?



I'm writing a special file parser and discovered that READ-CHAR is
*much* slower than READ-LINE, even though it does little consing.
Theoretically, READ-CHAR create its own buffer, so it sould be only
slightly slower than READ-LINE due to extra function invocations.

I thought I could be smart by creating my own buffer and filling it with
READ-CHAR.  Oh, well!

Below are stats for the same 140KByte file.  (Functions were compiled.)

(DEFUN TIME-TEST-CHAR (FILENAME)
  (WITH-OPEN-FILE (STREAM FILENAME)
    (TIME
      (LOOP WHILE (READ-CHAR STREAM NIL)))))

Evaluation of (LOOP WHILE #) took 83.996002 seconds of elapsed time including:
  1.177 seconds processing sequence breaks,
  0.179 seconds in the storage system (including 0.000 seconds waiting for pages):
    0.017 seconds processing 74 page faults including 0 fetches,
    0.004 seconds in creating and destroying pages, and
    0.158 seconds in miscellaneous storage system tasks.
336 list, 300 structure words consed in WORKING-STORAGE-AREA.



(DEFUN TIME-TEST-LINE (FILENAME)
  (WITH-OPEN-FILE (STREAM FILENAME)
    (TIME
      (LOOP WHILE (READ-LINE STREAM NIL)))))
	
Evaluation of (LOOP WHILE #) took 9.598611 seconds of elapsed time including:
  0.166 seconds processing sequence breaks,
  0.522 seconds in the storage system (including 0.000 seconds waiting for pages):
    0.026 seconds processing 111 page faults including 0 fetches,
    0.341 seconds in creating and destroying pages, and
    0.156 seconds in miscellaneous storage system tasks.
96 list, 38,360 structure words consed in WORKING-STORAGE-AREA.