home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / TPSTR121.ZIP / BENCHMRK.PAS next >
Encoding:
Pascal/Delphi Source File  |  1989-12-18  |  3.3 KB  |  94 lines

  1. program benchmark;
  2. uses crt,strings;
  3.  
  4. { NOTE: ITER is set to give good timing resolution on an IBM PC.  For
  5.   faster machines, to maintain the same resolution, it should be
  6.   increased roughly in proportion to the speed of the machine relative to
  7.   a PC. }
  8. const iter=1000;
  9.  
  10. var randstr,searchstr,temp1,temp2,temp3:string; i,j:byte; ii:word;
  11.     biostimer:longint absolute $0040:$006C;
  12.     elapsed:longint;
  13.  
  14. begin
  15.     clrscr;
  16.     randomize;
  17.     randstr[0]:=#255;
  18.     for i:=1 to 255 do randstr[i]:=chr(random(256));
  19.     searchstr:=substr(randstr,250,6);
  20.     writeln('Note: One timer tick is approximately 1/18th of a second.');
  21.  
  22. { compare POS & FIRSTPOS }
  23.  
  24.     writeln('Timing the TP POS function:');
  25.     elapsed:=biostimer;
  26.     for ii:=1 to iter do i:=pos(searchstr,randstr);
  27.     elapsed:=biostimer-elapsed;
  28.     writeln(iter,' iterations of POS takes ',elapsed,' clock ticks.');
  29.     writeln('Timing FIRSTPOS function:');
  30.     elapsed:=biostimer;
  31.     for ii:=1 to iter do j:=strings.firstpos(searchstr,randstr,1);
  32.     elapsed:=biostimer-elapsed;
  33.     writeln(iter,' iterations of FIRSTPOS takes ',elapsed,' clock ticks.');
  34.     if i=j then writeln('Results agree.')
  35.        else writeln('Results disagree!! what???');
  36.  
  37. { compare COPY and SUBSTR }
  38.  
  39.     writeln; writeln('Timing the TP COPY function:');
  40.     elapsed:=biostimer;
  41.     for ii:=1 to 4*iter do temp1:=copy(randstr,100,150);
  42.     elapsed:=biostimer-elapsed;
  43.     writeln(4*iter,' iterations of COPY takes ',elapsed,' clock ticks.');
  44.     writeln('Timing SUBSTR function:');
  45.     elapsed:=biostimer;
  46.     for ii:=1 to 4*iter do temp2:=strings.substr(randstr,100,150);
  47.     elapsed:=biostimer-elapsed;
  48.     writeln(4*iter,' iterations of SUBSTR takes ',elapsed,' clock ticks.');
  49.     if temp1=temp2 then writeln('Results agree.')
  50.        else writeln('Results disagree!! what???');
  51.  
  52. { compare INSERT and INSTR }
  53.  
  54.     writeln; writeln('Timing TP INSERT procedure:');
  55.     temp1:=substr(randstr,1,100);
  56.     temp2:=substr(randstr,101,50);
  57.     elapsed:=biostimer;
  58.     for ii:=1 to iter do insert(temp2,temp1,50);
  59.     elapsed:=biostimer-elapsed;
  60.     writeln(iter,' iterations of INSERT takes ',elapsed,' clock ticks.');
  61.     temp3:=temp1;
  62.     writeln('Timing INSTR function:');
  63.     temp1:=substr(randstr,1,100);
  64.     elapsed:=biostimer;
  65.     for ii:=1 to iter do temp1:=strings.instr(temp2,temp1,50,' ');
  66.     elapsed:=biostimer-elapsed;
  67.     writeln(iter,' iterations of INSTR takes ',elapsed,' clock ticks.');
  68.     if temp1=temp3 then writeln('Results agree.')
  69.        else writeln('Results disagree!! what???');
  70.  
  71. { compare DELETE and DELSTR }
  72.  
  73.     writeln; writeln('Timing TP DELETE procedure:');
  74.     temp1:=substr(randstr,1,100);
  75.     elapsed:=biostimer;
  76.     for ii:=1 to 2*iter do begin
  77.        temp2:=temp1;
  78.        delete(temp2,40,40);
  79.     end;
  80.     elapsed:=biostimer-elapsed;
  81.     writeln(2*iter,' iterations of DELETE takes ',elapsed,' timer ticks.');
  82.     writeln('Timing DELSTR function:');
  83.     elapsed:=biostimer;
  84.     for ii:=1 to 2*iter do begin
  85.        temp3:=temp1; { to keep things MORE than equal }
  86.        temp3:=strings.delstr(temp1,40,40);
  87.     end;
  88.     elapsed:=biostimer-elapsed;
  89.     writeln(2*iter,' iterations of DELSTR takes ',elapsed,' timer ticks.');
  90.     if temp2=temp3 then writeln('Results agree.')
  91.        else writeln('Results disagree!! what???');
  92.  
  93. end.
  94.