Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Side by side comparison (strings & local data)
Message
De
23/12/2003 13:36:12
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
23/12/2003 11:18:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
00861648
Message ID:
00861698
Vues:
30
>Hi all
>
>Just did a quick side-by-side comparison with C# and VFP8, the test is aimed at string building from local-data using ADO.Net & Fox's local data-engine, can anyone tell me if I've messed up in away or if there is a quicker way of doing this:
>
>Here's the VFP program:
>
>
>LOCAL lcXML
>lcXML = "<TEST>"
>
>*Start time
>SET DECIMALS TO 3
>
>USE C:\DEV\CSHARP\DEMO\DEMOS\DATA\CLIENT IN 0
>			
>SELECT * FROM Client WHERE UPPER(Cl_Sname) = "LAWRENCE" INTO CURSOR TEST NOFILTER
>
>=AFIELDS(laFields, "Test")
>
>StartTime = SECONDS()
>
>SCAN
>	lcXML = lcXML + "<CLIENT>"
>	FOR f = 1 TO ALEN(laFields, 1)
>		lcXML = lcXML + "<" + laFields(f, 1) + ">" + ;
>			TRANSFORM(EVALUATE("Test." + laFields(f, 1))) +;
>			"</" + laFields(f, 1) + ">"
>	ENDFOR
>	lcXML = lcXML + "</CLIENT>"
>ENDSCAN
>
>lcXML = lcXML + "</TEST>"
>
>*Show Time-Taken
>?SECONDS() - StartTime
>
>
>RESULT : Between 0.040 and 0.070 Seconds
>
>And here is the C# Version:
>
>
>public static void DataPerformance()
>	{
>	//Use Local FoxDB with lots of data
>	OleDbConnection Connection = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=c:\dev\csharp\Demo\Demos\Data\Client.DBF") ;
>	OleDbDataAdapter Result = new OleDbDataAdapter("SELECT * FROM Client WHERE UPPER(Cl_Sname) = 'LAWRENCE'", Connection) ;
>	DataSet Cursor = new DataSet() ;
>	Result.Fill(Cursor, "CLIENT") ;
>	StringBuilder XML = new StringBuilder() ;
>	DataColumn[] Columns = new DataColumn[Cursor.Tables["Client"].Columns.Count];
>	Cursor.Tables["Client"].Columns.CopyTo(Columns, 0) ;
>
>	//Start time
>	DateTime StartTime = DateTime.Now;
>
>	XML.Append("<Test>") ;
>	//Build XML Result
>	//Scans through what would be a local-cursor in Fox
>	foreach (DataRow Row in Cursor.Tables["CLIENT"].Rows)
>	{
>	        XML.Append("<CLIENT>") ;
>		for (int c = 0; c < Columns.Length; c++)
>			{
>				XML.Append("<" + Columns[c].ColumnName + ">" + Row[Columns[c].ColumnName].ToString() +
>					"</" + Columns[c].ColumnName + ">") ;
>			}
>			XML.Append("</CLIENT>") ;
>		}
>
>	XML.Append("</Test>") ;
>
>	//End Time
>	DateTime EndTime = DateTime.Now ;
>
>	//End
>	Console.WriteLine(StartTime) ;
>	Console.WriteLine(EndTime) ;
>	Console.WriteLine(EndTime-StartTime) ;
>}
>
>
>RESULT : 0.0100143 Seconds
>
>It may not be a relevent test, I think it is, but let me know. The table in question has 55000 records and the SELECT statment extracts 55 of those. The aim is to demenstrate VFP using a local-cursor and C# using a local ADO.Net DataSet.
>
>Apologies for those who can't read C#.
>
>Thanks

Kevin,
I think C# closes the gap and more wins with this code with the speed of stringbuilder. It's really very hard with few tests IMHO. However I never found VFP's string handling fast. It uses things like handles to memory locations. If you do like in your code :

lcXML = lcXML + someaddition

Adding over and over to same variable is not optimized at all. However that code might be optimized in different ways (in VFP there are at least 3 ways:). For the moment I'd only touch it slightly to beat proposed C# code with pure VFP (with 200K recs your C# did it in 132 secs vs VFP 18 secs -but I don't say VFP is 6-8 times faster than C#) :
*Start time
StartTime = SECONDS()
LOCAL lcXML

SELECT * ;
  FROM "C:\DEV\CSHARP\DEMO\DEMOS\DATA\CLIENT" ;
  WHERE UPPER(Cl_Sname) = "LAWRENCE" ;
  INTO CURSOR TEST 

=AFIELDS(laFields, "Test")

lcTemp = Sys(2015)+'.tmp'
lnHandle = fcreate(lcTemp)
Fputs(m.lnHandle,'<TEST>')
SCAN
	Fputs(m.lnHandle,"<CLIENT>")
	FOR f = 1 TO ALEN(laFields, 1) 
		Fputs(m.lnHandle,"<" + laFields(m.f, 1) + ">" + ;
			TRANSFORM(EVALUATE("Test." + laFields(m.f, 1))) +;
			"</" + laFields(m.f, 1) + ">")
	ENDFOR
	Fputs(m.lnHandle,"</CLIENT>")
ENDSCAN
Fputs(m.lnHandle,"</TEST>")
Fclose(m.lnHandle)
lcXML = FileToStr(m.lcTemp)
*Show Time-Taken
Erase (m.lcTemp)
?SECONDS() - StartTime
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform