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

Re: More file output performance



In article <poeck-140194191247@wina65.informatik.uni-wuerzburg.de>,
poeck@informatik.uni-wuerzburg.de (Karsten Poeck) wrote:

> More Data on slow/fast Lisp Mac File I/O:
In the meantime I found an answer inspired by  "TANSTAAFL" Rich
lynch@ils.nwu.edu.

Format seems to be very slow, when I do instead a recursive walk
on the s-expression, convert the pieces into strings and write
them with the  (stream-writer stream) functions to file the whole stuff
is about 5 times faster

Karsten


(declaim (inline save-a-string save-a-char))

(defun save-a-string (string function value)
  (dovector (char string)
    (funcall function value char)
    )
  )

(defun save-a-char (char function value)
  (funcall function value char)
  )

(defun format-a-sexp (outer-expression function value)
  (labels
    ((*do-it (expression)
       (if (null expression)
         nil
         (if (atom expression)
           (if (symbolp expression)
             (progn 
               (save-a-string (string expression) function value)
               (save-a-char #\space function value))
             (if (stringp expression)
               (progn 
                 (save-a-char #\" function value)
                 (save-a-string expression function value)
                 (save-a-char #\" function value))
               ;bad one
               (save-a-string (format nil "~s " expression) function
value)))
           (progn
             ;a list
             (save-a-char #\( function value)
             (dolist (was expression)
               (*do-it was))
             (save-a-string ") " function value))))))
    (*do-it outer-expression)
    (save-a-char #\newline function value))
  )


(defun save-a-symbol (symbol stream function value)
  (declare (ignore stream))
  (format-a-sexp `(setf (symbol-plist ',symbol) ',(symbol-plist symbol))
function value)
  )

(defun save-a-sexp-to-an-open-stream (s-exp stream)
  (multiple-value-bind
    (a b)
    (stream-writer stream)
    (format-a-sexp s-exp a b)))

#|
(let ((file (merge-pathnames "test.knowledgebase")))
  (when (probe-file file)
    (delete-file file))
  (time
   (save-knowledge-base file)))

(Save-Knowledge-Base File) took 8123 milliseconds (8.123 seconds) to run.
Of that, 99 milliseconds (0.099 seconds) were spent in The Cooperative
Multitasking Experience.
 36440 bytes of memory allocated.

|#