Strange optimization timings
Posted: Sat May 03, 2008 1:41 pm
I thought I'd test the speed difference between using the swap command and using a temporary variable so I tried this bit of code
(make sure you turn off the debugger first)
so it appears that the temp variable is faster, but then I thought I'd print both results at the same time to make it easier to see so I did this
and now the swap routine is 25% faster but nothing in the timing loops has been altered and the messagerequester() was outside of the timing so why should the first routine get so much faster. Nothing changed?
(make sure you turn off the debugger first)
Code: Select all
min.f=100.55
mean.f=55.34
max.f=33.21
a=0
For m=1 To 10
t=ElapsedMilliseconds()
For n=1 To 100000000
If max<mean
Swap max,mean
EndIf
If mean<min
Swap mean,min
EndIf
If max<mean
Swap max,mean
EndIf
Next
t=ElapsedMilliseconds()-t
a+t
Next
MessageRequester("",Str(a/10))
min.f=100.55
mean.f=55.34
max.f=33.21
a=0
For m=1 To 10
t=ElapsedMilliseconds()
For n=1 To 100000000
If max<mean
tq.f=max
max=mean
mean=tq
EndIf
If mean<min
tq.f=mean
mean=min
min=tq
EndIf
If max<mean
tq.f=max
max=mean
mean=tq
EndIf
Next
t=ElapsedMilliseconds()-t
a+t
Next
MessageRequester("",Str(a/10))
;970 885
;948 887
;962 895
;996 882
;1007 895
Code: Select all
min.f=100.55
mean.f=55.34
max.f=33.21
a=0
For m=1 To 10
t=ElapsedMilliseconds()
For n=1 To 100000000
If max<mean
Swap max,mean
EndIf
If mean<min
Swap mean,min
EndIf
If max<mean
Swap max,mean
EndIf
Next
t=ElapsedMilliseconds()-t
a+t
Next
a2=a
min.f=100.55
mean.f=55.34
max.f=33.21
a=0
For m=1 To 10
t=ElapsedMilliseconds()
For n=1 To 100000000
If max<mean
tq.f=max
max=mean
mean=tq
EndIf
If mean<min
tq.f=mean
mean=min
min=tq
EndIf
If max<mean
tq.f=max
max=mean
mean=tq
EndIf
Next
t=ElapsedMilliseconds()-t
a+t
Next
MessageRequester("",Str(a2/10)+" "+Str(a/10))
;970 885
;948 887
;962 895
;996 882
;1007 895
;770 896
;770 896
;768 898
;771 896