Maybe Olivier asks for a better code optimization?
Or better control for logical functions (NOT ) ?
Or just some possibilities to keep user defined variables in CPU registers when possible?
Or something completely different?
;*******************
; And gate test
;*******************
DisableDebugger
; FIRST MODULE
Delay(1)
Begin1 = ElapsedMilliseconds()
For A = 0 To 8000
For B = 0 To 8000
If A And B
EndIf
Next B
Next A
Finish1 = ElapsedMilliseconds()
; SECOND MODULE
Delay(1)
Begin2 = ElapsedMilliseconds()
For A = 0 To 8000
For B = 0 To 8000
If A
If B
EndIf
EndIf
Next B
Next A
Finish2 = ElapsedMilliseconds()
Duration1.F = Finish1 - Begin1
Duration2.F = Finish2 - Begin2
MessageRequester("AND Gate tests", "First module : " + Str(Finish1 - Begin1) + Chr(10) + "Second module : " + Str(Finish2 - Begin2) + Chr(10) + "Duration difference = " + Str(Int(100.0 * Duration2 / Duration1) - 100) + "%")
Kaeru Gaman wrote:I suspect it would highly depend on the complexity of the conditions and the size of the codesections to execute
with simplest conditions and to code in between, what would be the point in testing it?
anyhow,
it would be nice to know WHY this result occurs,
and it IS nice to know that more-and-simpler lines is faster than less-and-more-complex lines.
;
; FIRST MODULE ; SECOND MODULE
; ;
; If a And b ; If a
CMP dword [v_a],0 CMP dword [v_a],0
JE No0 JE _EndIf12
; If b
CMP dword [v_b],0 CMP dword [v_b],0
JE No0 JE _EndIf14
Ok0:
MOV eax,1
JMP End0
No0:
XOR eax,eax
End0:
AND eax,eax
JE _EndIf6
; Code inside conditional goes here ; Code inside conditional goes here
; EndIf ; EndIf
_EndIf14:
; EndIf
_EndIf6: _EndIf12:
It seems there's twice as many commands in the First Module's assembled code. My guess is that the simplified method of the Second Module can only be applied to multiple And conditions. When combined with other conditionals (Or and Not) it can get a little more complicated to translate. As a result the more general method of the First Module is used with multiple conditional expressions with the tradeoff of speed.
@Ollivier: if your method could be extended (or specified more completely) somewhat I think it would be adopted by Fred (I hope), barring some other complication.
Last edited by Demivec on Sun Jun 07, 2009 12:35 pm, edited 1 time in total.
The test is flawed. The conditions are true once and false 63999999 times, which is not very balanced.
Also, there would realistically be some code within the condition, so let's add some. Suddenly the And version is faster.
I think that the If version is faster with no code within because the processor branch prediction detects that the check is senseless and does some optimizations based on that.
; FIRST MODULE
Delay(1)
Begin1 = ElapsedMilliseconds()
For A = 0 To 10000
For B = 0 To 10000
If A&1 And B&1
somecode+goes-here
EndIf
Next B
Next A
Finish1 = ElapsedMilliseconds()
; SECOND MODULE
Delay(1)
Begin2 = ElapsedMilliseconds()
For A = 0 To 10000
For B = 0 To 10000
If A&1
If B&1
somecode+goes-here
EndIf
EndIf
Next B
Next A
Finish2 = ElapsedMilliseconds()
Duration1.d = Finish1 - Begin1
Duration2.d = Finish2 - Begin2
MessageRequester("AND Gate tests", "First module : " + Str(Finish1 - Begin1) + Chr(10) + "Second module : " + Str(Finish2 - Begin2) + Chr(10) + "Duration difference = " + Str(Int(100.0 * Duration2 / Duration1) - 100) + "%")