[NTG-context] Variable instance identifiers exhausted

Hans Hagen j.hagen at xs4all.nl
Wed Sep 19 23:23:10 CEST 2018


On 9/19/2018 10:45 PM, Alan Braslau wrote:
> Metapost does not have a very efficient mechanism for keeping objects in memory and does not have a very efficient or real array mechanism, rather it uses hashed lists.

fwiw, keeping objects as such in memory is quite ok, hashing is also ok, 
but indeed arrays are not really arrays but linked lists into the hash

(which actually you can speed up a lot)

so, here is a teaser for Alan (no lua magic here, just knowledge of how 
mp hashes):

\dontleavehmode \testfeatureonce{1}{
     \startMPcode
         numeric foo[];

         def set_foo(expr c, s) =
             foo[c]:= s ;
         enddef ;
         def get_foo(expr c) =
             foo[c]
         enddef ;

         for i=1 upto 10000 :
             set_foo(i,i) ;
         endfor ;

         draw textext("set one dimensional");
     \stopMPcode
} \elapsedtime \blank

\dontleavehmode \testfeatureonce{1}{
     \startMPcode
         numeric n ;
         for i=1 upto 10000 :
             n := get_foo(i) ;
         endfor ;

         draw textext("get one dimensional");
     \stopMPcode
} \elapsedtime \blank


\dontleavehmode \testfeatureonce{1}{
     \startMPcode
         numeric foo[][][][];

         def set_foo(expr c, s) =
             foo[c div 1000][c div 100][c div 10][c] := s ;
         enddef ;
         def get_foo(expr c) =
             foo[c div 1000][c div 100][c div 10][c]
         enddef ;

         for i=1 upto 10000 :
             set_foo(i,i) ;
         endfor ;

         numeric n ;
         for i=1 upto 10000 :
             n := get_foo(i) ;
         endfor ;

         draw textext("set four dimensional" );
     \stopMPcode
} \elapsedtime \blank

\dontleavehmode \testfeatureonce{1}{
     \startMPcode
         numeric n ;
         for i=1 upto 10000 :
             n := get_foo(i) ;
         endfor ;

         draw textext("get four dimensional");
     \stopMPcode
} \elapsedtime \blank


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 ntg-context mailing list