Thorium wrote:Oh, i just saw you didnt actualy step fractions, so whats the point of your benchmark?
Correct, but Thorium did not tell you why. A variable without type that is used for the first time in the program becomes automatically an integer type, that is, with the extension .i, and your variable x has no extension, so it becomes x.i
Then, your variable y, also without extension, so it becomes y.i and even when you wrote y=0.00001 it becomes y=0.
So, the first time that the variable y is used, it must have the extension .d (for a double) or .f (for floating point) so y.d=0.000001 will work.
But then, your variable x cannot be incremented with 0.000001 because it is an integer, thus if you want to have x with decimals, you need to declare it as a double or a floating: x.d or x.f
Once the variable has been declared (with the statement Declare or by adding an extension), you can omit the extension, because it is known.
With code you can understand it much better:
Code: Select all
DisableDebugger
StartTime=ElapsedMilliseconds()
a.i = 1
b.i = 1
For i = 1 To 2000000000
a = a * b
Next i
ElapsedTime=ElapsedMilliseconds()-StartTime
et.d=ElapsedTime/1000
MessageRequester("Timer",Str(ElapsedTime)+" milliseconds, meaning "+StrD(et,2)+" seconds.")
StartTime=ElapsedMilliseconds()
x.d = 1
y.d = 1.0000000001
For i = 1 To 2000000000
x = x * y
Next i
ElapsedTime=ElapsedMilliseconds()-StartTime
et.d=ElapsedTime/1000
MessageRequester("Timer",Str(ElapsedTime)+" milliseconds, meaning "+StrD(et,2)+" seconds.")
StartTime=ElapsedMilliseconds()
i = 1
x.d = 1
y.d = 1.0000000001
While i <= 2000000000 ; NOT decreased to 2000000
x = x * y
i = i + 1
Wend
ElapsedTime=ElapsedMilliseconds()-StartTime
et.d=ElapsedTime/1000
MessageRequester("Timer",Str(ElapsedTime)+" milliseconds, meaning "+StrD(et,2)+" seconds.")
EnableDebugger
On my computer, the first example takes 5 seconds, the second examples takes 7.5 seconds, and the third one 7.5 seconds as well.
As you see, using integers is 33% faster.
krzysztof wrote:But when we talk about advantages of "while wend" loop of Pure, we have to compare it to "for to next " loop in other dialects, I think. Pure is easy??? Hmmm, not for me.
Not necessarily. Every programming language is constructed on base of a solid idea, and the For-Next were implemented only for simple high speed loops. For slower loops (with decimals or with variable step), a While-Wend or Repeat-Until should be used.
As long as there is a way to do what we want to achieve, we may be very happy!
