read_list



On 5/21/07, Thomas Widlar <twidlar at yahoo.com> wrote:
>
> The original file is about 3.12MB, about 208,000 floating point numbers
> of zero. I tried it again. About an hour later, wxmaxima still says
> "Maxima

is calculating" consuming 99% of the  CPU.


I took a look at the code.  It is clearly not intended for large inputs, as
read_list contains an n^2 algorithm, where it repeatedly appends to the
*end* of an accumulation list, requiring n^2/2 cons's. At the cost of
slightly trickier code, we can improve efficiency for large inputs. Here's
the performance comparison on GCL, 1GHz, W2k:

Size   Count    Old time   New time
 75k   15,000    3 sec      2 sec
150k   30,000   14 sec      5 sec
300k   60,000   64 sec     11 sec

I didn't have the patience to try larger files...

I'm updating the code in CVS, and including it below.

               -s


(defun $read_list (file-name &optional sep-ch-flag)
  (let ((A '()) (L))
    (setq file-name (require-string file-name))
    (with-open-file (in file-name :if-does-not-exist nil)
      (cond
       ((not (null in))
    (let ((sep-ch (get-input-sep-ch sep-ch-flag file-name)))
      (loop
       (setq L (read-line in nil 'eof))
       (if (eq L 'eof)
           (return (cons '(mlist simp) (nreverse A))))
       (setq A (nreconc (cdr (make-mlist-from-string L sep-ch)) A)))))
       (t (merror "read_list: ~S: no such file" file-name))))))