reading a large array
Qiong Cai <[email protected]>
| Newsgroups | gmane.comp.tex.metapost |
|---|---|
| Message-ID | <CAOrq85EF7zZyJopxXN_oqviTK-XSm8GoHk5R9e7VycEnWLEX-A@mail.gmail.com> |
Hi,
Here's the code to read an array of data from a file.
vardef readFromFile(suffix a)(text filename) =
numeric c;
c := 0;
string s;
forever:
s := readfrom filename;
exitif s = EOF;
a[c] := s;
c := c+1;
endfor
c
enddef;
The performance of this function on my iMac (3.xGHz, Intel SKL) is shown
below
10 numbers: 0.096 seconds
100: 0.096
1K: 0.10
10K: 0.463
100K: 1m23seconds
1M: after 15 minutes, still not finishing
It seems that from 100K to 1M, it's getting slower every 10K or 1K. I guess
the memory allocator in metapost pre-allocates certain memory and copies
the whole memory when the array increases. Is that the case? If so, could
we improve the memory allocation in metapost?
Thanks
Qiong
--
http://tug.org/metapost/