speed of LOCATE command in X# vs VFP
Posted: Thu Sep 17, 2020 12:03 am
hi boys
I am a XSHARP tester to migrate from VFP Applications and i agree with Loy. We can use the power of the .Net Framework to resolve X# situations but a simple loop is really important, FoxPro is 27 times faster than XSharp
I think that at least a brief look at the performance is important to give ideas to minimize the differences. Don't get me wrong, I consider tha
I'm sure csharp is the best project ever to migrate to .net from FoxPro
Below I paste the source code tested in both environments
* FOXPRO 0.4 SECONDS
*************************************************
LOCAL lalias
If Used("w03oper")
lalias= "w03operTMP"
Else
lalias= "w03oper"
Endif
sqlexec("SELECT distinct top 1000 * from m03oper" , lalias) <---- lalias has 153 columns
If Used("w03operTMP")
Zap In W03OPER
Select W03operTMP
GO top
Do While !Eof("W03operTMP") <----- performance problems begin
Scatter Name lbuff
Select W03OPER
Append Blank
Gather Name lbuff
Select W03operTMP
Skip
ENDDO <----- performance problem end
Use In W03operTMP
ENDIF
*********************************************************************************
* XSHARP 11 seconds
***************************************************************************************
If Used(w03oper)
lalias= "w03operTMP"
Else
lalias= "w03oper"
Endif
d_sql("SELECT distinct top 1000 * from m03oper" , lalias)
If Used("w03operTMP")
Zap In w03oper"
Select W03operTMP
GO top
private mcache
Do While !Eof("W03operTMP")
//Scatter Name lbuff
LBUFF = ScatterTo(mcache)
SELECT W03oper
APPEND BLANK
GatherFrom(Lbuff)
Select W03operTMP
Skip
Enddo
ENDIF
********
FUNCTION ScatterTo(mcache ref Array) AS Dictionary<STRING,USUAL>
oReturn := Dictionary<STRING,USUAL>{}
if empty(mcache)
mcache:= DBStruct()
endif
AEval(mcache, {|afield,index|;
oReturn:Add(aField[DBS_NAME], FieldGet(index));
})
RETURN oReturn
*****************************************************
FUNCTION GatherFrom(aData AS Dictionary<STRING,USUAL>) AS LOGIC
LOCAL nFld AS DWORD
LOCAL nMax AS DWORD
local actual:= alias()
foreach f as KeyValuePair<STRING,USUAL> in aData
TRY
fieldputalias(actual,f:Key,f:Value)
CATCH e as Exception
d_log ("gather error" + f:key + ":"+ transform(f:Value,""), e:ToString())
RETURN FALSE
END TRY
endfor
return true
I am a XSHARP tester to migrate from VFP Applications and i agree with Loy. We can use the power of the .Net Framework to resolve X# situations but a simple loop is really important, FoxPro is 27 times faster than XSharp
I think that at least a brief look at the performance is important to give ideas to minimize the differences. Don't get me wrong, I consider tha
I'm sure csharp is the best project ever to migrate to .net from FoxPro
Below I paste the source code tested in both environments
* FOXPRO 0.4 SECONDS
*************************************************
LOCAL lalias
If Used("w03oper")
lalias= "w03operTMP"
Else
lalias= "w03oper"
Endif
sqlexec("SELECT distinct top 1000 * from m03oper" , lalias) <---- lalias has 153 columns
If Used("w03operTMP")
Zap In W03OPER
Select W03operTMP
GO top
Do While !Eof("W03operTMP") <----- performance problems begin
Scatter Name lbuff
Select W03OPER
Append Blank
Gather Name lbuff
Select W03operTMP
Skip
ENDDO <----- performance problem end
Use In W03operTMP
ENDIF
*********************************************************************************
* XSHARP 11 seconds
***************************************************************************************
If Used(w03oper)
lalias= "w03operTMP"
Else
lalias= "w03oper"
Endif
d_sql("SELECT distinct top 1000 * from m03oper" , lalias)
If Used("w03operTMP")
Zap In w03oper"
Select W03operTMP
GO top
private mcache
Do While !Eof("W03operTMP")
//Scatter Name lbuff
LBUFF = ScatterTo(mcache)
SELECT W03oper
APPEND BLANK
GatherFrom(Lbuff)
Select W03operTMP
Skip
Enddo
ENDIF
********
FUNCTION ScatterTo(mcache ref Array) AS Dictionary<STRING,USUAL>
oReturn := Dictionary<STRING,USUAL>{}
if empty(mcache)
mcache:= DBStruct()
endif
AEval(mcache, {|afield,index|;
oReturn:Add(aField[DBS_NAME], FieldGet(index));
})
RETURN oReturn
*****************************************************
FUNCTION GatherFrom(aData AS Dictionary<STRING,USUAL>) AS LOGIC
LOCAL nFld AS DWORD
LOCAL nMax AS DWORD
local actual:= alias()
foreach f as KeyValuePair<STRING,USUAL> in aData
TRY
fieldputalias(actual,f:Key,f:Value)
CATCH e as Exception
d_log ("gather error" + f:key + ":"+ transform(f:Value,""), e:ToString())
RETURN FALSE
END TRY
endfor
return true