KRASCHE
&
BYRNE
         ELZED  HOME       NEWS       DOCS       DOWNLOADS       LICENSING       SUPPORT       FAQ       ABOUT  US

What's An Elzed?
Features
Licensing
Downloads
Documentation
Elzed News
    ELZED 
 Documentation 
 Examples 
 Sample Code 

Loop Performance Sample Code

void TimingTest( long lTestType )
{
	char		theExpression[ 128 ];
	char		szTestType[ 32 ];

	bool		bResult;

	long		lInnerLoop;
	long		lOuterLoop;
	
	long		lStartTime;
	long		lEndTime;
	long		lResolveIndex;
	
	double		dWazoo = 0.0;
	double		dFester = 0.0;
	double		dResult = 0.0;
	long		lTests = 5000000;
	double		dCompiledTime;
	double		dParserTime;

	LZObjectHandle	hContextID = 0;
	LZObjectHandle	hExpression = 0;
	
	lzClearContext();
	lzCreatePrivateContext( "TimingTest" );
	hContextID = lzSetContext( "TimingTest", false );
	
	lzEvalExpStrToNum( "global number fester; global number wazoo; fester=wazoo=0" );
	
	if ( lzGetLastErrorID() )
		cout << lzGetLastErrorText() << '\n';
	
	switch ( lTestType )
	{
	case 70:	// "Internal" Loop
		strcpy( szTestType, "Internal Loop" );
		
		strcpy( theExpression, "tests=5000000; until (tests-- < 0) do fester++; wazoo += fester^2 + 5*fester - 10; next; return wazoo" );
		//strcpy( theExpression, "tests = -5000000; until (tests++ > 0) do wazoo += sqrt(tests); next; return wazoo" );
		//strcpy( theExpression, "tests = 5000000; until (tests-- < 0) do wazoo += sqrt(tests); next; return wazoo" );
		
		lzEvalExpStrToNum( "global number fester; global number wazoo; fester=wazoo=0" );
		hExpression = lzParseExp( theExpression );
				
		if ( lzGetLastErrorID() )
			cout << lzGetLastErrorText() << '\n';

		cout.flush();
		lStartTime = clock();
		dWazoo = lzEvalExpHndlToNum( hExpression );
		break;

	case 80:	// "External" loop
		strcpy( szTestType, "External Loop" );
		
		// Expressions from Gary Beene's review of parsers...
		//  http://www.garybeene.com/reviews/rev-parsers.htm

		//strcpy( theExpression, "fester*2+wazoo*2" );
		//strcpy( theExpression, "sin(fester)+sin(wazoo)" );
		//strcpy( theExpression, "fester^2+wazoo^2" );
		strcpy( theExpression, "abs(sin(sqrt(fester^2+wazoo^2))*255)" );
		//strcpy( theExpression, "abs(sin(sqrt(fester*fester+wazoo*wazoo))*255)" );

		lzLinkNumVar( 'G', "wazoo", &dWazoo );
		lzLinkNumVar( 'G', "fester", &dFester );

		hExpression = lzParseExp( theExpression );
				
		if ( lzGetLastErrorID() )
			cout << lzGetLastErrorText() << '\n';

		lInnerLoop = 2000;
		lOuterLoop = 2000;

		lTests = lInnerLoop * lOuterLoop;

		cout.flush();
		lStartTime = clock();

		for ( dFester = 1; dFester <= lOuterLoop; dFester++ )
			for ( dWazoo = 1; dWazoo <= lInnerLoop; dWazoo++ )
				dResult = lzEvalExpHndlToNum( hExpression );

		break;

	default:
		strcpy( szTestType, "No Test Selected" );
		cout.flush();
		lStartTime = clock();
		break;
	}

	lEndTime = clock();
	
	cout << dResult << '\n' << '\n';

	dParserTime = lEndTime - lStartTime;
	
	cout << szTestType << '\n';
	cout << "Elapsed time (ticks): " << (lEndTime - lStartTime) << '\n' << '\n';
	cout <<	"MIPS: " << (lTests / (dParserTime / MIPS_CONSTANT)) << '\n';
	cout.flush();
	
	lzClearContext();
	lzDestroyPrivateContext( "TimingTest" );
	
	lzReset();
}


  Copyright  ©  MMXXV  by  R R Le Cropane   •   All Rights Reserved   •   Terms of Use   •   Privacy Policy