[metapost] reading a large array

Qiong Cai qiong.cai at gmail.com
Fri Mar 10 01:56:59 CET 2017


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20170309/7a0711e3/attachment.html>


More information about the metapost mailing list