home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21056 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.2 KB

  1. Path: sparky!uunet!mcsun!sun4nl!tuegate.tue.nl!svin09!wsinfo01!wstomv
  2. From: wstomv@wsinfo01.win.tue.nl (Tom Verhoeff)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Why is new(p) so slow in THINK Pascal?
  5. Summary: Further tests reveal quadratic behavior of new and NewPtr
  6. Keywords: THINK Pascal, dynamic variables, Memory Manager
  7. Message-ID: <4946@svin09.info.win.tue.nl>
  8. Date: 8 Jan 93 22:49:18 GMT
  9. References: <4940@svin09.info.win.tue.nl>
  10. Sender: news@svin09.info.win.tue.nl
  11. Reply-To: wstomv@win.tue.nl
  12. Organization: Eindhoven Univ. of Technology, The Netherlands
  13. Lines: 58
  14.  
  15. Further tests of the slow THINK Pascal memory allocation procedure New
  16. reveal that there is some quadratic behavior involved.
  17.  
  18.     # news        time (in seconds)
  19.     ------        -----------------
  20.      1000          3 (probably 2.61 by extrapolation)
  21.      2000         11
  22.      3162         26
  23.      5000         66
  24.     10000        261
  25.  
  26. Note that 3162/1000 approximates the square root of 10.  The conclusion
  27. seems to be that  k  times more new calls require  k-squared  more time
  28. to execute.
  29.  
  30. The calls to new in my test program are done successively in a tight for loop;
  31. the new pointers are to records which are linked in a chain.
  32. Afterwards, this chain is disposed of in a flash (less than one second,
  33. almost independent of its length).  Here is a program:
  34.  
  35.     program NewTest;
  36.     type List = ^Element;
  37.          Element = record key: Longint; next: List end;
  38.     var head, p: List; k, n: Longint;
  39.     begin
  40.     MaxApplZone;
  41.     head := nil;
  42.     write('How many times? '); readln(n);
  43.     write('Newing ', N:1, ' times;');
  44.     for k := 1 to N do begin
  45.       new(p);
  46.       with p^ do begin
  47.         key := k;
  48.         next := head;
  49.         end; { with p^ }
  50.       head := p;
  51.       end; { for k }
  52.     writeln(' done.'); write('Disposing ')
  53.     k:=0;
  54.     while head <> nil do begin
  55.       p := head;
  56.       head := head^.next;
  57.       dispose(p);
  58.       k := succ(k);
  59.       end; { while }
  60.     writeln(k:1,' times; done.');
  61.     end.
  62.  
  63. Furthermore, the numbers are exactly the same when new is replaced by an
  64. appropriately type-casted call of the Memory Manager's NewPtr function.
  65.  
  66. Anyone got a clue yet what is going on here?
  67.  
  68.     Tom
  69. -- 
  70. INTERNET: wstomv@win.tue.nl  /    Eindhoven University of Technology
  71. VOICE: +31 40 47 41 25      /    Dept of Mathematics & Computing Science
  72. FAX: +31 40 43 66 85       /    PO Box 513, NL-5600 MB Eindhoven, Netherlands
  73.