home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!tuegate.tue.nl!svin09!wsinfo01!wstomv
- From: wstomv@wsinfo01.win.tue.nl (Tom Verhoeff)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Why is new(p) so slow in THINK Pascal?
- Summary: Further tests reveal quadratic behavior of new and NewPtr
- Keywords: THINK Pascal, dynamic variables, Memory Manager
- Message-ID: <4946@svin09.info.win.tue.nl>
- Date: 8 Jan 93 22:49:18 GMT
- References: <4940@svin09.info.win.tue.nl>
- Sender: news@svin09.info.win.tue.nl
- Reply-To: wstomv@win.tue.nl
- Organization: Eindhoven Univ. of Technology, The Netherlands
- Lines: 58
-
- Further tests of the slow THINK Pascal memory allocation procedure New
- reveal that there is some quadratic behavior involved.
-
- # news time (in seconds)
- ------ -----------------
- 1000 3 (probably 2.61 by extrapolation)
- 2000 11
- 3162 26
- 5000 66
- 10000 261
-
- Note that 3162/1000 approximates the square root of 10. The conclusion
- seems to be that k times more new calls require k-squared more time
- to execute.
-
- The calls to new in my test program are done successively in a tight for loop;
- the new pointers are to records which are linked in a chain.
- Afterwards, this chain is disposed of in a flash (less than one second,
- almost independent of its length). Here is a program:
-
- program NewTest;
- type List = ^Element;
- Element = record key: Longint; next: List end;
- var head, p: List; k, n: Longint;
- begin
- MaxApplZone;
- head := nil;
- write('How many times? '); readln(n);
- write('Newing ', N:1, ' times;');
- for k := 1 to N do begin
- new(p);
- with p^ do begin
- key := k;
- next := head;
- end; { with p^ }
- head := p;
- end; { for k }
- writeln(' done.'); write('Disposing ')
- k:=0;
- while head <> nil do begin
- p := head;
- head := head^.next;
- dispose(p);
- k := succ(k);
- end; { while }
- writeln(k:1,' times; done.');
- end.
-
- Furthermore, the numbers are exactly the same when new is replaced by an
- appropriately type-casted call of the Memory Manager's NewPtr function.
-
- Anyone got a clue yet what is going on here?
-
- Tom
- --
- INTERNET: wstomv@win.tue.nl / Eindhoven University of Technology
- VOICE: +31 40 47 41 25 / Dept of Mathematics & Computing Science
- FAX: +31 40 43 66 85 / PO Box 513, NL-5600 MB Eindhoven, Netherlands
-