Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which is faster: array or cursor?
Message
From
14/03/2009 12:57:53
 
 
To
13/03/2009 05:18:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01386748
Message ID:
01388070
Views:
87
Really interesting indeed :)

Thank You Cetin

Sergio





>>Hi Cetin,
>>
>>Thank you for the code! However, NET languages are this point little bit ahead of my schedue;
>>I was interested actually in technique of splitting text into words via combo with fox that you mentioned.
>>
>>Sergio is my nickname for past 30 years, so I got used to it completely.
>>If someone was to shout 'Srdjan' on the street, I would barely turn my head to see who else
>>have the same maiden name, but would not think it is actually someone calling me...
>>
>>So eighter one is fine with me :)
>
>Here is a test code using differrent techniques (also showing fastest way of concatenating a string is lowlevel file IO - IMHO):
>
>Local lcDizi, lnElements, lnStrLen,xTime
>lnStrLen = 20
>lnElements = 10000
>lcDizi = CreateCommaSeparatedIntList(m.lnElements)
>
>Clear
>xTime = Seconds()
>Test1(m.lcDizi)
>?"Test1 : ", Seconds() - m.xTime
>
>xTime = Seconds()
>Test2(m.lcDizi)
>?"Test2 : ", Seconds() - m.xTime
>
>xTime = Seconds()
>Test3(m.lcDizi)
>?"Test3 : ", Seconds() - m.xTime
>
>*** Worst - don't even attempt to test if iteration is not very low ***
>*!*	xTime = Seconds()
>*!*	Test4(m.lcDizi)
>*!*	?"Test4 : ", Seconds() - xTime
>
>xTime = Seconds()
>Test5(m.lcDizi)
>?"Test5 : ", Seconds() - m.xTime
>
>*** Next to Worst ***
>*!*	xTime = Seconds()
>*!*	Test6(m.lcDizi)
>*!*	?"Test6 : ", Seconds() - m.xTime
>
>Procedure CreateCommaSeparatedIntList(tnCount)
>  Rand(-1)
>  Local lcTemp,lnHandle,lcString,ix
>  lcTemp = Forcepath( Sys(2015)+'.tmp',Sys(2023))
>  lnHandle = Fcreate(m.lcTemp)
>  For ix = 1 To m.tnCount
>    If m.ix > 1
>      Fwrite(m.lnHandle,',')
>    Endif
>    Fwrite(m.lnHandle, Ltrim(Str(Rand()*0x7FFFFFFF)))
>  Endfor
>  Fclose(m.lnHandle)
>  lcString = Filetostr(m.lcTemp)
>  Erase (m.lcTemp)
>  Return m.lcString
>Endproc
>
>Procedure Test1(tcDizi)
>  Local Array arrH[1]
>  Local ix
>  For ix = 1 To Alines(arrH, Chrtran(m.tcDizi,',',Chr(13)))
>    arrH[m.ix] = Int(Val(arrH[m.ix]))
>  Endfor
>Endproc
>
>Procedure Test2(tcDizi)
>  Local Array arrH[1]
>  Local ix
>  For ix = 1 To Alines(arrH,m.tcDizi,.F.,',')
>    arrH[m.ix] = Int(Val(arrH[m.ix]))
>  Endfor
>Endproc
>
>Procedure Test3(tcDizi)
>  Local oDummy,ix
>  oDummy = Createobject('Listbox')
>  With oDummy
>    .RowSourceType = 1 && Value
>    .RowSource = m.tcDizi
>    Local Array arrH[.ListCount]
>    For ix=1 To .ListCount
>      arrH[m.ix] = Int(Val(.List(m.ix)))
>    Endfor
>  Endwith
>  Release oDummy
>Endproc
>
>Procedure Test4(tcDizi)
>  Local Array arrH[OCCURS(',',m.tcDizi)+1]
>  Local ix
>  ix=1
>  Do While Occurs(',',m.tcDizi)>0
>    arrH[m.ix] = Int(Val(Substr(m.tcDizi,1,At(',',m.tcDizi)-1)))
>    ix=m.ix+1
>    tcDizi = Substr(m.tcDizi,At(',',m.tcDizi)+1)
>  Enddo
>  arrH[m.ix] = Int(Val(m.tcDizi))
>Endproc
>
>Procedure Test5(tcDizi)
>  lcTemp = Sys(2015)+'.tmp'
>  Strtofile(Chrtran(m.tcDizi,',',Chr(13)), lcTemp)
>  Create Cursor Dummy (Dummy i)
>  Append From (lcTemp) Type Sdf
>  Copy To Array arrH
>  Use
>  Erase (lcTemp)
>Endproc
>
>Procedure Test6(tcDizi)
>  Local lnCount
>  lnCount = Occurs(',', m.tcDizi) + 1
>  Local Array arrH[m.lnCount]
>  For ix = 1 To m.lnCount
>    arrH[m.ix] = Getwordnum(m.tcDizi, m.ix, ',')
>  Endfor
>Endproc
>
Cetin
*****************
Srdjan Djordjevic
Limassol, Cyprus

Free Reporting Framework for VFP9 ;
www.Report-Sculptor.Com
Previous
Reply
Map
View

Click here to load this message in the networking platform