BTreeSimpleTest: Commander.CommandProc = {
myTree: BTreeSimple.Tree;
writeBacking, readBacking: IO.STREAM;
msPerOp: ARRAY Operation OF REAL;
refs, reads, writes: CARD;
hitPercent, msPerReadWrite, avgChainLength: REAL;
filename: ROPE ¬ NIL;
iterations: CARD ¬ 0;
okay: BOOLEAN ¬ TRUE;
IO.PutRope[cmd.out, "Name of file to hold BTree: "];
filename ¬ IO.GetLineRope[cmd.in];
IF filename =
NIL
THEN {
filename ¬ "BTreeTest.tree"; -- default filename
};
IO.PutRope[cmd.out, "Number of iterations to perform: "];
iterations ¬ Convert.CardFromRope[
IO.GetLineRope[cmd.in] !
Convert.Error => {IO.PutRope[cmd.out, "Error from BTreeSimpleTest: not a number\n"]; RETRY}
];
writeBacking ¬ PFS.StreamOpen[PFS.PathFromRope[filename], $write];
readBacking ¬ PFS.StreamOpen[PFS.PathFromRope[filename], $read];
myTree ¬ Create[readBacking, writeBacking, 500];
[msPerOp] ¬RunTest[myTree, iterations ! Error =>
{IO.PutF[cmd.out, "Error from BTreeSimpleTest: %g - %g\n", IO.atom[ec], IO.rope[explanation]];
CONTINUE};
];
FOR operation: Operation
IN Operation
DO {
opname: ROPE ¬ NIL;
SELECT operation
FROM
lookup => opname ¬ "lookup";
validate => opname ¬ "validate";
insert => opname ¬ "insert";
delete => opname ¬ "delete";
replace => opname ¬ "replace";
ENDCASE;
IO.PutF[cmd.out, " %g = %g msec\n", IO.rope[opname], IO.real[msPerOp[operation]]];
};
ENDLOOP;
IO.PutRope[cmd.out, "\n Virtual memory statistics.\n\n"];
[refs, reads, writes, hitPercent, msPerReadWrite, avgChainLength] ¬ GetVMStats[myTree];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Hits and misses"], IO.card[refs]];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Reads"], IO.card[reads]];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Writes"], IO.card[writes]];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Percentage hit"], IO.real[hitPercent]];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Milliseconds per read/write"], IO.real[msPerReadWrite]];
IO.PutF[cmd.out, " %g = %g \n", IO.rope["Average chain length"], IO.real[avgChainLength]];
Flush anything remaining on 'backing' stream, and close it
IO.Flush[writeBacking];
IO.Close[writeBacking];
IO.Close[readBacking];
};
}.