Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C++ can speed up native VFP strings command ?
Message
 
To
20/11/2003 12:25:13
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00851950
Message ID:
00852234
Views:
10
Fabio,

I compared VFP and C++ on your program. The C++ code is below (I used At() and Occurs() implementations from VFPDotNet library).
My results on PIII-1000 (in seconds):

VFP: 4.75 (OCCURS), 0.38 (AT)
C++: 0.37 (OCCURS), 0.34 (AT)

Yes, we see some performance problems with OCCURS, but, in general, it is not too bad. The speed of AT function is about the same.
// strTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "strTest.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

static int Occurs(CString cString, CString &cExpression)
{
	int nPos = 0;
	int nOccured = 0;
	do
	{
		//Look for the search string in the expression
		nPos = cExpression.Find(cString,nPos);

		if (nPos < 0)
		{
			//This means that we did not find the item
			break;
		}
		else
		{
			//Increment the occured counter based on the current mode we are in
			nOccured++;
			nPos++;
		}
	} while (true);

	//Return the number of occurences
	return nOccured;
}

static int At(CString cSearchFor, CString &cSearchIn, int nOccurence)
{
	//In this case we actually have to locate the occurence
	int i = 0;
	int nOccured = 0;
	int nPos = 0;

	//Loop through the string and get the position of the requiref occurence
	for (i=1;i<=nOccurence;i++)
	{
		nPos = cSearchIn.Find(cSearchFor,nPos);

		if (nPos < 0)
		{
			//This means that we did not find the item
			break;
		}
		else
		{
			//Increment the occured counter based on the current mode we are in
			nOccured++;

			//Check if this is the occurence we are looking for
			if (nOccured == nOccurence)
			{
				return nPos + 1;
			}
			else
			{
				nPos++;
			}
		}
	}
	//We never found our guy if we reached here
	return 0;
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		CString sString, sTmp;

		// Replicate('a',100)
		sTmp = ",";
		for (int i = 0; i < 100; i++)
		{
			sTmp += 'a';
		}

		for (i = 0; i < 20; i++)
		{
			sString += sTmp;
		}
		cout << "Lenght = " << sString.GetLength() << endl;

		int res;
		int t1 = GetTickCount();
		for (int k = 1; k < 50000; k++)
			res = Occurs(",",sString);
		cout << "OCCURS " << GetTickCount()-t1 << endl;

		t1 = GetTickCount();
		for (k = 1; k < 50000; k++)
			res = At(",",sString,20);
		cout << "AT " << GetTickCount()-t1 << endl;
	}

	return nRetCode;
}
>Normally one believes that the string functions of VFP are much fast;
>this is correct, but it is not a general rule.
>
>If the routines of AT and OCCURS they were both written best,
>time for execute the request would have to be practically identical.
>
>Then, exist native VFP command that C++ can speedup.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform