<div dir="ltr">Hi,<div><br></div><div>Here's the code to read an array of data from a file.</div><div><span class="gmail-s1"><br></span></div><div><span class="gmail-s1">vardef</span><span class="gmail-s2"> readFromFile(</span><span class="gmail-s1">suffix</span><span class="gmail-s2"> a)(</span><span class="gmail-s1">text</span><span class="gmail-s2"> filename) =</span></div><div><span class="gmail-s2"> </span><span class="gmail-s3">numeric</span><span class="gmail-s2"> c;</span></div><div><span class="gmail-s2"> c := </span><span class="gmail-s4">0</span><span class="gmail-s2">;</span></div><div><span class="gmail-s3"> string</span><span class="gmail-s2"> s;</span></div><div><span class="gmail-s2"> forever</span><span class="gmail-s5">:</span></div><div> s := readfrom filename;</div><div><span class="gmail-s1"> exitif</span><span class="gmail-s2"> s = </span><span class="gmail-s6">EOF</span><span class="gmail-s2">;</span></div><div> a[c] := s;</div><div><span class="gmail-s2"> c := c+</span><span class="gmail-s4">1</span><span class="gmail-s2">;</span></div><div> endfor</div><div> c</div><div>
<p class="gmail-p2"><span class="gmail-s2">enddef</span><span class="gmail-s5">;</span></p><p class="gmail-p2"><span class="gmail-s5"><br></span></p><p class="gmail-p2"><span class="gmail-s5">The performance of this function on my iMac (3.xGHz, Intel SKL) is shown below </span></p><p class="gmail-p2"><span class="gmail-s5">10 numbers: 0.096 seconds</span></p><p class="gmail-p2"><span class="gmail-s5">100: 0.096</span></p><p class="gmail-p2"><span class="gmail-s5">1K: 0.10</span></p><p class="gmail-p2"><span class="gmail-s5">10K: 0.463</span></p><p class="gmail-p2"><span class="gmail-s5">100K: 1m23seconds</span></p><p class="gmail-p2"><span class="gmail-s5">1M: after 15 minutes, still not finishing</span></p><p class="gmail-p2">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?</p><p class="gmail-p2"><br></p><p class="gmail-p2">Thanks</p><p class="gmail-p2">Qiong </p><p class="gmail-p2"><span class="gmail-s5"><br></span></p><p class="gmail-p2"><span class="gmail-s5"><br></span></p></div></div>