/* Stringtest.b

	This program will show the timings of several ACE string functions.
	To get a speed comparison between the original ACE string functions
	and the new stringlib ones, you will have to :

	1) Make the Stringtest.b program. (compile and link)
	2) Execute it and get the timings...
	3) Link the Stringtest.o Stringlib.o with the normal ACE link libraries.
		ex.: Phxlnk Stringtest.o Stringlib.o ACELIB:startup.lib ACELIB:db.lib ACELIB:ami.lib
		Beware! Stringlib.o MUST come before the ACE link libraries!
	4) Execute it again...and smile...;-)

  Notes:	Do not use the FULL option when optimizing with SuperOptimizer V2.01.
			It will inline most of the string functions, so you will see no
			improvement at all...

			CacheClearU() is called to flush all cache entries, to prevent
			silly timings.

			This test program can take some time...specially on a plain
			A1200.

			I could have 'beautified' the output a bit more, but this was
			not it's main purpose...

*/


LIBRARY "exec.library"

DECLARE FUNCTION Forbid() LIBRARY exec
DECLARE FUNCTION Permit() LIBRARY exec
DECLARE FUNCTION CacheClearU() LIBRARY exec


LONGINT Char

STRING Source SIZE 1024
STRING Part SIZE 1024
STRING Dest SIZE 1024

Forbid

Part="Get hold of the new ACE stringlib! It's a good thing to do... ;-)"

Part=Part+Part


/* Get dead time figure... */

T!=TIMER

FOR T%=1 to 32000

	CacheClearU

NEXT

SUBTIME!=TIMER-T!

PRINT "Testing INSTR(Part,'G')           ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,"G")
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,')')           ";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,")")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,'ACE')         ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,"ACE")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,'a good')      ";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,"a good")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,'a good thing')";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(42,Part,"a good thing")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,Part)          ";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,Part)

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(3,Part,Part)        ";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(3,Part,Part)

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,'a good think')";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,"a good think")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing INSTR(Part,'X')           ";
T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=INSTR(Part,"X")

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT

PRINT "Testing Char=LEN('a')                  ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=LEN("a")
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Char=LEN('abc')                ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=LEN("abc")
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Char=LEN('abcdefgh')           ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=LEN("abcdefgh")
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Char=LEN('abcdefghijklmnopqrs')";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=LEN("abcdefgh")
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Char=LEN(Part)                 ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Char=LEN(Part)
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT

PRINT "Testing Dest='a'                  ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Dest="a"
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Dest='abc'                ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Dest="abc"
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Dest='abcdefgh'           ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Dest="abcdefgh"
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Dest='abcdefghijklmnopqrs'";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Dest="abcdefghijklmnopqrs"
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT "Testing Dest=Part                 ";

T!=TIMER

FOR T%=1 to 32000

	CacheClearU
	Dest=Part
NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

PRINT

FOR RIGHT%=1 TO 80 STEP 10

	PRINT "Testing RIGHT$(Part,"+STR$(RIGHT%)+").         ";

	T!=TIMER

	FOR T%=1 to 32000

		CacheClearU
		Dest=RIGHT$(Part,RIGHT%)

	NEXT

	RESULT!=TIMER-T!

	RESULT!=RESULT!-SUBTIME!

	PRINT " Took";RESULT!;"seconds."

NEXT

PRINT

FOR RIGHT%=1 TO 80 STEP 10

	PRINT "Testing LEFT$(Part,"+STR$(RIGHT%)+").          ";

	T!=TIMER

	FOR T%=1 to 32000

		CacheClearU
		Dest=LEFT$(Part,RIGHT%)

	NEXT

	RESULT!=TIMER-T!

	RESULT!=RESULT!-SUBTIME!

	PRINT " Took";RESULT!;"seconds."

NEXT

PRINT

FOR RIGHT%=1 TO 80 STEP 10

	PRINT "Testing MID$(Part,"+STR$(RIGHT%\4)+","+STR$(RIGHT%)+").         ";

	T!=TIMER

	FOR T%=1 to 32000

		CacheClearU
		Dest=MID$(Part,SHR(RIGHT%,4),RIGHT%)

	NEXT

	RESULT!=TIMER-T!

	RESULT!=RESULT!-SUBTIME!

	PRINT " Took";RESULT!;"seconds."

NEXT

PRINT

PRINT "Testing string concatenation.     ";

Part="a"

T!=TIMER

FOR X%=1 TO 9

	Dest=""

	FOR T%=1 to 1000\LEN(Part)

		CacheClearU
		Dest=Dest+Part

	NEXT

	Part=Part+Part

NEXT

RESULT!=TIMER-T!

RESULT!=RESULT!-SUBTIME!

PRINT " Took";RESULT!;"seconds."

Permit

END
