Hi,
Preface:
I can do this sum:
x = x + y
with this algorithm ?:
for iLoop=1 to y
x = x +1
endfor
Yes, but it is a hugly implementation,
and if i can do it faster without effort, it is a bug for me.
Well.
Why on VFP LEN() function use a similar algorithm for return the lenght
of a string ?
VFP use binary strings; it do not use a end string special character.
Then, the lenght of the string is on the internal "value structure"
of the variable string ( like on Pascal ).
API section of the help reference to this value with:
cVal->ev_length syntax.
Then, i aspected LEN() speed independent by the lenght of the string,
as a
O(1) complexity,
but this is not true,
it is a
O(N) complexity.
Run this:
CLEAR
SET ESCAPE ON
memString = SPACE(1)
t1=SECONDS()
FOR j=1 TO 5000000
strLenght = LEN(m.memString)
NEXT
? TRANSFORM(5000000/(SECONDS()-m.t1),'@R string lengh = 1 999,999,999,999 vfops/s')
memString = SPACE(10000000)
t1=SECONDS()
FOR j=1 TO 100
strLenght = LEN(m.memString)
NEXT
? TRANSFORM(100/(SECONDS()-m.t1),'@R string lengh = 1000000 999,999,999,999 vfops/s')
If VFP9 remove the 16MB string lenght limit, to get the LEN() of a 2GB string
can require many seconds !
Post notes:
I see various comparison between VFP and .NET,
but this is only a relative comparison; like to compare :
a) a photon with a electron particles,
b) a F-16 Airforce with a Piper airplanes,
c) a Ferrari with a Fiat cars
d) a tortoise with a snail animals.
Photon is the best real limit!
Somebody known if the best VFP and .NET comprison analogy is a),b),c) or d) ?
One or two past years, i thought b), but with the recent experiences ....
Fabio