Code: Select all
a = a / 2
Code: Select all
a = a / 2
Code: Select all
m = ElapsedMilliseconds()
For i = 0 To 100000000
tmp = Random(500)
x = tmp / 2
Next
t = ElapsedMilliseconds() - m
m = ElapsedMilliseconds()
For i = 0 To 100000000
tmp = Random(500)
If tmp % 2 = 0
x = tmp >> 1
Else
x = tmp / 2
EndIf
Next
t2 = ElapsedMilliseconds() - m
MessageRequester("Normal Division by 2", Str(t))
MessageRequester("Shift Replacement if modulo 2", Str(t2))
I was actually just changing the size of the letters, but then decided to add the original post for readabilityAnd actually, you don't need to be afraid of me changing the meaning of
my post after you posted. I would not do something like that to make you
look wrong.
NO I did not run it with the debugger onmilan1612 wrote:Did you run it without debugger?thefool wrote:On my computer, the second one is definently not faster. In fact its 40% slower
I get 3568 normal division, 3172 with shift optimization (average values)
Code: Select all
m = ElapsedMilliseconds()
!align 4
For i = 0 To 100000000
tmp = Random(500)
x = tmp / 2
Next
t = ElapsedMilliseconds() - m
m = ElapsedMilliseconds()
!align 4
For i = 0 To 100000000
tmp = Random(500)
If tmp % 2
x = tmp >> 1
Else
x = tmp / 2
EndIf
Next
t2 = ElapsedMilliseconds() - m
MessageRequester("", Str(t))
MessageRequester("", Str(t2))
Why? In both loops the Random() gets called the same times, so it's irrelevant...remi_meier wrote:ou wait, nobody here seems to know, what he's doing.
nothing against you, milan, but your speed-test is the worst I've seen in
a long time. at least 99% of the time in the loops is spent on the Random()
function. Nothing really to say about the >>1 thingy.
Code: Select all
#nums = 50000000
Dim numbers.l(#nums)
For i = 0 To #nums
numbers(i) = Random(5000)
Next
m = ElapsedMilliseconds()
For i = 0 To #nums
x = numbers(i) / 2
Next
t = ElapsedMilliseconds() - m
m = ElapsedMilliseconds()
For i = 0 To #nums
If numbers(i) % 2 = 0
x = numbers(i) >> 1
Else
x = numbers(i) / 2
EndIf
Next
t2 = ElapsedMilliseconds() - m
MessageRequester("Normal Division by 2", Str(t))
MessageRequester("Shift Replacement if modulo 2", Str(t2))
warning: takes a bit time to run.;first generate a set of numbers
Dim seta(30000000)
For i=0 To 30000000
seta(i)=Random(500)
Next i
;allright.
For a=1 To 20
m=ElapsedMilliseconds()
For i=0 To 30000000
;here goes the code
tmp=seta(i)
x=tmp/2
Next i
t=t+(ElapsedMilliseconds()-m)
Next a
t=t/20
For a=1 To 20
m=ElapsedMilliseconds()
For i=0 To 30000000
;here goes the code
tmp = seta(i)
If tmp % 2
x = tmp >> 1
Else
x = tmp / 2
EndIf
Next i
t2=t2+(ElapsedMilliseconds()-m)
Next a
t2=t2/20
MessageRequester("divide with 2",Str(t))
MessageRequester("the other",Str(t2))