[metapost] reading a large array

Hans Hagen pragma at wxs.nl
Fri Mar 10 15:03:42 CET 2017


On 3/10/2017 1:56 AM, Qiong Cai wrote:
> Hi,
>
> Here's the code to read an array of data from a file.
>
> vardefreadFromFile(suffixa)(textfilename) =
>     numericc;
>     c := 0;
>     strings;
>     forever:
>         s := readfrom filename;
>         exitifs = 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?

btw, if you have more string indices than mp can handle (exceed the 
numeric limitations) you get an error and mp will take a while to build 
that message (as it gets enormous)

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the metapost mailing list