Rick Strahl's Weblog
Rick Strahl's FoxPro and Web Connection Weblog
White Papers | Products | Message Board | News |
Posted in: FoxPro

Feedback for this Weblog Entry


Re: Workaround for horrendously slow SUBSTR Character Parsing in FoxPro



Christof Wollenhaupt
July 05, 2020

It'll be faster if you copy the string into memory and then use SYS(2600) to read byte by byte.

LOCAL lnX, lcString
lcString = REPLICATE("1234567890",100000)

	Declare Integer HeapAlloc in Win32Api Integer, Integer, Integer
	Declare Integer HeapFree in Win32APi Integer, Integer, Integer
	Declare Long GetProcessHeap in Win32API
      
lnLength = LEN(lcString)
TRANSFORM(lnLength,"9,999,999")

IF .T.
lnSecs = SECONDS()

lnBase = HeapAlloc( GetProcessHeap(), 0, m.lnLength )
Sys(2600, m.lnBase, m.lnLength, m.lcString)
FOR lnX = 1 TO lnLength
	lcVal = Sys(2600,m.lnBase-1+m.lnX,1)
ENDFOR
HeapFree( GetProcessHeap(), 0, m.lnBase )

? "SYS(2600): " +  TRANSFORM(SECONDS() - lnSecs )

ENDIF

That's 0.33 seconds on my machine vs 37 seconds with SUBSTR().

Re: Workaround for horrendously slow SUBSTR Character Parsing in FoxPro



Rick Strahl
July 06, 2020

@Christof - that's great! Another great solution - looks like roughly on par with Marco's improvement.

 
© Rick Strahl, West Wind Technologies, 2003 - 2026