home *** CD-ROM | disk | FTP | other *** search
- {
- MyTest.Pas by Richard S. Sadowsky
- Released to the public domain
- 6/18/88, Los Angeles, California
-
- This program tests two similar routines. One is written in Turbo C,
- assembled to asm, and doctored to assemble to a TP4 ready OBJ file,
- and the other routine is the same algorithm implemented in Turbo
- Pascal. This illustrates that a significant speed advantage can
- be obtained by using C for certain algorithms.
-
- NOTE: This code is compiled with RANGE and STACK checking turned off.
- This is only fair, since the Turbo C does not check for this.
-
- See the files:
- MYTEST.PAS - This program
- MY.C - The Turbo C routine
- MY.ASM - The ASM output generated by TCC (see MY.C for more info)
- MY_P.ASM - ASM file doctored for use with Turbo Pascal
- MY_P.OBJ - The masm generated OBJ file for use with $L
- MYTEST.EXE - A precompiled example of this program
- READ.ME - A readme file to point you in the right direction
-
- To recompile and do this yourself, you will need Turbo Pascal version 4,
- Turbo C version 1 or 1.5 (I used 1.5), and a MASM compatable assembler
- (I used MASM 5.1). If you not have these, I have included the precompiled
- MYTEST.EXE, so you can see the speed difference for yourself.
-
- This program, MYTEST.PAS, prompts the user for a string. The string
- is then converted to uppercase 5000 times, first with the C routine
- then with the Pascal routine. The times for the process are shown and
- compared for each routine.
- }
- {$R-,S-,I-}
- program MyTest;
-
- uses TPDOS; { needed for TimeMS routine, although any timer will do }
-
- {$F+} {since the C routine is declared FAR, so is the Pascal routine }
-
- procedure StrUpr(var S : String); External; { written in C in file MY.C }
- {$L MY_P.obj}
-
- procedure P_StrUpr(var S : String); { same algorithm in pascal }
- { this is functionally and logically equivelent to the C routine }
- { StrUpr from the file My.C. }
- var
- Len,Counter : Integer;
- C : Char;
-
- begin
- Len := Length(S);
- for Counter := 1 to Len do begin
- C := S[Counter];
- if ((Ord(C) >= Ord('a')) and (Ord(C) <= Ord('z'))) then
- S[Counter] := Chr(Ord(C) - 32)
- else
- S[Counter] := C;
- end;
- end;
-
- var
- S,SS : String;
- T1,T2,TP,TC : LongInt;
- I : Word;
-
- begin
- Write('Enter a string : ');
- ReadLn(S); { get a string to uppercase from user }
- T1 := TimeMS; { starting time for C routine }
- for I := 1 to 5000 do begin
- SS := S;
- StrUpr(SS); { upper case the string 5000 times using C routine }
- end;
- T2 := TimeMS; { stopping time for C routine }
- WriteLn(SS); { show the uppercase string once }
- TC := T2 - T1; { calculate number of milliseconds for C routine }
- WriteLn('TC time = ',TC);
- T1 := TimeMS; { starting time for pascal routine }
- for I := 1 to 5000 do begin
- SS := S;
- P_StrUpr(SS); { upper case the string 5000 times using Pascal routine }
- end;
- T2 := TimeMS; { stopping time for pascal routine }
- WriteLn(SS); { show the uppercase string once }
- TP := T2 - T1; { calculate number of milliseconds for pascal routine }
- WriteLn('TP time = ',TP);
- WriteLn('Difference is ',TP - TC); {show difference (TC routine is faster)}
- end.