Category : Pascal Source Code
Archive   : STRING.ZIP
Filename : BENCHMRK.PAS

 
Output of file : BENCHMRK.PAS contained in archive : STRING.ZIP
program benchmark;
uses crt,strings;

{ NOTE: ITER is set to give good timing resolution on an IBM PC. For
faster machines, to maintain the same resolution, it should be
increased roughly in proportion to the speed of the machine relative to
a PC. }
const iter=1000;

var randstr,searchstr,temp1,temp2,temp3:string; i,j:byte; ii:word;
biostimer:longint absolute $0040:$006C;
elapsed:longint;

begin
clrscr;
randomize;
randstr[0]:=#255;
for i:=1 to 255 do randstr[i]:=chr(random(256));
searchstr:=substr(randstr,250,6);
writeln('Note: One timer tick is approximately 1/18th of a second.');

{ compare POS & FIRSTPOS }

writeln('Timing the TP POS function:');
elapsed:=biostimer;
for ii:=1 to iter do i:=pos(searchstr,randstr);
elapsed:=biostimer-elapsed;
writeln(iter,' iterations of POS takes ',elapsed,' clock ticks.');
writeln('Timing FIRSTPOS function:');
elapsed:=biostimer;
for ii:=1 to iter do j:=firstpos(searchstr,randstr,1);
elapsed:=biostimer-elapsed;
writeln(iter,' iterations of FIRSTPOS takes ',elapsed,' clock ticks.');
if i=j then writeln('Results agree.')
else writeln('Results disagree!! what???');

{ compare COPY and SUBSTR }

writeln; writeln('Timing the TP COPY function:');
elapsed:=biostimer;
for ii:=1 to 4*iter do temp1:=copy(randstr,100,150);
elapsed:=biostimer-elapsed;
writeln(4*iter,' iterations of COPY takes ',elapsed,' clock ticks.');
writeln('Timing SUBSTR function:');
elapsed:=biostimer;
for ii:=1 to 4*iter do temp2:=substr(randstr,100,150);
elapsed:=biostimer-elapsed;
writeln(4*iter,' iterations of SUBSTR takes ',elapsed,' clock ticks.');
if temp1=temp2 then writeln('Results agree.')
else writeln('Results disagree!! what???');

{ compare INSERT and INSTR }

writeln; writeln('Timing TP INSERT procedure:');
temp1:=substr(randstr,1,100);
temp2:=substr(randstr,101,50);
elapsed:=biostimer;
for ii:=1 to iter do insert(temp2,temp1,50);
elapsed:=biostimer-elapsed;
writeln(iter,' iterations of INSERT takes ',elapsed,' clock ticks.');
temp3:=temp1;
writeln('Timing INSTR function:');
temp1:=substr(randstr,1,100);
elapsed:=biostimer;
for ii:=1 to iter do temp1:=instr(temp2,temp1,50,' ');
elapsed:=biostimer-elapsed;
writeln(iter,' iterations of INSTR takes ',elapsed,' clock ticks.');
{in spite of the overhead of the assignment of the function result!}
{what is TP doing??}
if temp1=temp3 then writeln('Results agree.')
else writeln('Results disagree!! what???');

{ compare DELETE and DELSTR }

writeln; writeln('Timing TP DELETE procedure:');
temp1:=substr(randstr,1,100);
elapsed:=biostimer;
for ii:=1 to 2*iter do begin
temp2:=temp1;
delete(temp2,40,40);
end;
elapsed:=biostimer-elapsed;
writeln(2*iter,' iterations of DELETE takes ',elapsed,' timer ticks.');
writeln('Timing DELSTR function:');
elapsed:=biostimer;
for ii:=1 to 2*iter do begin
temp3:=temp1; { to keep things MORE than equal }
temp3:=delstr(temp1,40,40);
end;
elapsed:=biostimer-elapsed;
writeln(2*iter,' iterations of DELSTR takes ',elapsed,' timer ticks.');
if temp2=temp3 then writeln('Results agree.')
else writeln('Results disagree!! what???');

end.


  3 Responses to “Category : Pascal Source Code
Archive   : STRING.ZIP
Filename : BENCHMRK.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/