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

[72110.1107@CompuServe.COM: File output performance]

   From: "Bruce Lester [Pillsbury]" <72110.1107@CompuServe.COM>
   To: MCL bulletin board <info-macl@cambridge.apple.com>
   Subject: File output performance

   >I am trying to improve the performance of a section of a program that creates a
   >simple ASCII text file.  It takes forever (about 45 minutes to create a 1 MEG.

   >Is there a way I could buffer the file output or do something else to improve

   >The following is a section of some code I wrote to create an ASCII file from a
   >CLOS data structure:

Try this if you always want to print all the columns of a row.  If you only
want to print a set number of rows, then use another 'dotimes call with
columns. (I didn't actually run this so you may have a couple of changes)

New code:
  (let ((str (make-string-output-stream)))
    ;; dotimes always starts at 0, so kludge it abit
    (dotimes (i (1- rows) (close file-stream))
      (declare (fixnum rows))
      ;; Can we assume we are ouputing ALL columns???
      (let ((row-data (assoc (1+ i) (data table-symbol))))
       (write-string (first row-data) str)
       (format str "~{,~A~}~%" (cdr row-data))
       ;; dump out the string stream for each row to the file
       (format file-stream "~A" (get-output-stream-string str)))))