File: TestAllocation.mesa
Last Edited by: Stolfi, April 23, 1984 4:07:22 pm PST
Tests the efficiency of allocation/deallocation.
DIRECTORY
Buttons USING [ButtonProc, Create],
MessageWindow USING [Append],
Convert USING [RopeFromCard],
Rope USING [ROPE],
BasicTime USING [Pulses, GetClockPulses, PulsesToMicroseconds];
TestAllocation: CEDAR MONITOR
IMPORTS Buttons, MessageWindow, BasicTime, Convert = 
BEGIN OPEN Rope;
BlahPtr: TYPE = REF BlahRec;
BlahRec: TYPE = RECORD
[foo, bar: REF BlahRec,
baz: INT ← 0,
quux: LIST OF REF ANYNIL,
zed: REF BlahRec ← NIL,
oinc: ARRAY [1..3] OF INTALL[1]];
blahs: ARRAY [0..100) OF BlahPtr ← ALL [NIL];
lists: ARRAY [1..91) OF LIST OF REF ANYALL [NIL];
seed: INTEGER ← 27;
stopWatch: BasicTime.Pulses;
flist: LIST OF REF ANYNIL;
nil: LIST OF REF ANYNIL;
MyCons: PROCEDURE [a: REF ANY, b: LIST OF REF ANY] RETURNS [r: LIST OF REF ANY] = {
IF flist # NIL THEN
{r ← flist; flist ← flist.rest; r.first ← a; r.rest ← b}
ELSE
{r ← CONS[a, b]}
};
Foo: PROCEDURE [a: REF ANY, b: LIST OF REF ANY] RETURNS [r: LIST OF REF ANY] = {
RETURN[nil]
};
Reclaim: PROCEDURE [r: LIST OF REF ANY] = {
IF r # NIL THEN
{r.first ← NIL; r.rest ← flist; flist ← r}
};
Start: PROCEDURE [r: ROPE] = {
MessageWindow.Append["Testing ", TRUE];
MessageWindow.Append[r];
MessageWindow.Append["... "];
MessageWindow.Append["... "];
stopWatch ← BasicTime.GetClockPulses[]};
Stop: PROCEDURE = {
MessageWindow.Append["Done "];
MessageWindow.Append[Convert.RopeFromCard
[BasicTime.PulsesToMicroseconds[BasicTime.GetClockPulses[] - stopWatch] ]]
};
Rand: PROCEDURE RETURNS [r: INTEGER] = INLINE {
seed ← seed+1; IF seed >= 91 THEN seed ← 1;
RETURN [seed]
};
TestConsProc: ENTRY Buttons.ButtonProc = {
[parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL]
r: INTEGER;
Start["CONS"];
THROUGH [1..10] DO
MessageWindow.Append["+"];
THROUGH [1..10000] DO
r ← Rand[];
lists[r] ← CONS[lists[Rand[]], lists[Rand[]]]
ENDLOOP
ENDLOOP;
Stop[]
};
TestFooProc: ENTRY Buttons.ButtonProc = {
[parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL]
r: INTEGER;
Start["Foo"];
THROUGH [1..10] DO
MessageWindow.Append["+"];
THROUGH [1..10000] DO
r ← Rand[];
lists[r] ← Foo[lists[Rand[]], lists[Rand[]]]
ENDLOOP
ENDLOOP;
Stop[]
};
TestBlahProc: ENTRY Buttons.ButtonProc = {
[parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL]
r: INTEGER;
Start["NEW BlahRec"];
THROUGH [1..10] DO
MessageWindow.Append["+"];
THROUGH [1..10000] DO
r ← Rand[];
blahs[r] ← NEW[BlahRec ← [foo: blahs[Rand[]], bar: blahs[Rand[]]]]
ENDLOOP
ENDLOOP;
Stop[]
};
TestMyConsProc: ENTRY Buttons.ButtonProc = {
[parent: REF ANY, clientData: REF ANY, mouseButton: MouseButton, shift, control: BOOL]
r: INTEGER;
Start["MyCons"];
THROUGH [1..10] DO
MessageWindow.Append["+"];
THROUGH [1..10000] DO
r ← Rand[];
Reclaim[lists[r]];
lists[r] ← MyCons[lists[Rand[]], lists[Rand[]]]
ENDLOOP
ENDLOOP;
Stop[]
};
[] ← Buttons.Create[
info: [
name: "Cons",
parent: NIL],
proc: TestConsProc,
documentation: "Tests times for Cons+garbage collection."];
[] ← Buttons.Create[
info: [
name: "Foo",
parent: NIL],
proc: TestFooProc,
documentation: "Calibrates times."];
[] ← Buttons.Create[
info: [
name: "Blah",
parent: NIL],
proc: TestBlahProc,
documentation: "Tests times for big record allocation."];
[] ← Buttons.Create[
info: [
name: "MyCons",
parent: NIL],
proc: TestMyConsProc,
documentation: "Tests times for home-made Cons & Garbator."];
END.
CHANGE LOG
Created by Stolfi on April 9, 1984 6:52:06 pm PST