Posted: Mon Jun 08, 2009 1:41 pm
Code: Select all
@Trond: With your code I get -23% -> -28% .
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
@Trond: With your code I get -23% -> -28% .
Code: Select all
DisableDebugger
Macro ExecutionIfTrue()
; Nothing
EndMacro
Macro Test1()
If A
If B
ExecutionIfTrue()
EndIf
EndIf
EndMacro
Macro Test2()
If A And B
ExecutionIfTrue()
EndIf
EndMacro
Macro Test3() ; (= If A And B) /!\ /!\ /!\ /!\ /!\
!Lea esi,[v_A]
!Lodsd
!And eax,[v_B]
!JNE l_istrue
; Code execution if false
!JMP l_wasfalse
IsTrue:
; Code execution if true
ExecutionIfTrue()
WasFalse:
EndMacro ; \!/ \!/ \!/ \!/ \!/
Macro Counter(InternalMacro)
Cumul = 0
For A = 0 To 1
For B = 0 To 1
!Rdtsc
!Mov [v_ValeurIni], EAX
InternalMacro
!Rdtsc
!Mov [v_ValeurFin], EAX
Cumul + (ValeurFin - ValeurIni)
Next
Next
EndMacro
Define Test1.I
Define Test2.I
Define Test3.I
Define ValeurIni.I
Define ValeurFin.I
Define Cumul.I
Define A.I = 0
Define B.I = 0
Define TotalTest.I = 1
For I = 1 To TotalTest
Counter(Test1() ): Test1 + (Cumul / (1 << 2))
Counter(Test2() ): Test2 + (Cumul / (1 << 2))
Counter(Test3() ): Test3 + (Cumul / (1 << 2))
Next
MessageRequester("Tests without debugger", "Test #1 (If a If b) = " + Str(Test1) + " cycles" + Chr(10) + "Test #2 (If a And b) = " + Str(Test2) + " cycles" + Chr(10) + "Test #3 (Asm /!\ with ESI reg) = " + Str(Test3) + " cycles")
Are you sure?Trond wrote:The test is flawed. The conditions are true once and false 63999999 times, which is not very balanced.
Code: Select all
For A = 0 To 8000
For B = 0 To 8000
If A
If B
EndIf
EndIf
Next B
Next A
Are you again sure? I want to believe you. So, could you give me the links which tell me which processor family is excluded?Trond wrote:Rdtsc is not reliable on modern processors
Are you again sure?Which code example could you give me to prove it?Trond wrote:DisableDebugger is not enough
Code: Select all
Macro Test3() ; (= If A And B) /!\ /!\ /!\ /!\ /!\
!Lea esi,[v_A]
!Lodsd
!And eax,[v_B]
!JNE l_istrue
; Code execution if false
!JMP l_wasfalse
IsTrue:
; Code execution if true
WasFalse:
EndMacro ; \!/ \!/ \!/ \!/ \!/
Code: Select all
If A And B
EndIf
Code: Select all
DisableDebugger
timeBeginPeriod_(1)
Macro ExecutionIfTrue()
; Nothing
EndMacro
Macro Test1()
If A
If B
ExecutionIfTrue()
EndIf
EndIf
EndMacro
Macro Test2()
If A And B
ExecutionIfTrue()
EndIf
EndMacro
Macro Test3() ; (= If A And B) /!\ /!\ /!\ /!\ /!\
!Lea esi,[v_A]
!Lodsd
!And eax,[v_B]
!JNE l_istrue
; Code execution if false
!JMP l_wasfalse
IsTrue:
; Code execution if true
ExecutionIfTrue()
WasFalse:
EndMacro ; \!/ \!/ \!/ \!/ \!/
Macro Counter(InternalMacro)
Cumul = 0
For A = 0 To 1
For B = 0 To 1
InternalMacro
Next
Next
EndMacro
Define Test1.I
Define Test2.I
Define Test3.I
Define ValeurIni.I
Define ValeurFin.I
Define Cumul.I
Define A.I = 0
Define B.I = 0
Define TotalTest.I = 10000000
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test1() )
Next
ValeurFin=timeGetTime_()
Test1=ValeurFin-ValeurIni
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test2() )
Next
ValeurFin=timeGetTime_()
Test2=ValeurFin-ValeurIni
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test3() )
Next
ValeurFin=timeGetTime_()
Test3=ValeurFin-ValeurIni
MessageRequester("Tests without debugger", "Test #1 (If a If b) = " + Str(Test1) + " ms" + Chr(10) + "Test #2 (If a And b) = " + Str(Test2) + " ms" + Chr(10) + "Test #3 (Asm /!\ with ESI reg) = " + Str(Test3) + " ms")
timeEndPeriod_(1)
Compile Without DebuggerTest #1 (If a If b) = 214 ms
Test #2 (If a And b) = 237 ms
Test #3 (Asm /!\ with ESI reg) = 200 ms
As you can see there is a difference.Test #1 (If a If b) = 213 ms
Test #2 (If a And b) = 263 ms
Test #3 (Asm /!\ with ESI reg) = 204 ms
No, actually, I was wrong. There were 64016001 iterations. In 64000000 the check was true. In 16001 the check was false. I still claim that this is not balanced, though.Ollivier wrote:@Trond... Mh...
Are you sure?Trond wrote:The test is flawed. The conditions are true once and false 63999999 times, which is not very balanced.
... code...
Really sure?
Code: Select all
For A = 0 To 8000
For B = 0 To 8000
If A
If B
True + 1
EndIf
EndIf
Iter + 1
Next
Next
MessageRequester("", "Number of iterations: " + Str(Iter))
MessageRequester("", "Of which were true: " + Str(True))
MessageRequester("", "Of which were false: " + Str(Iter-True))
All processors with multi-core, or systems with multiple processors, and all processors with cpu frequency scaling ("speedstep").Are you again sure? I want to believe you. So, could you give me the links which tell me which processor family is excluded?Trond wrote:Rdtsc is not reliable on modern processors
Yes, I'm sure. Fred should know, he made PB: http://www.purebasic.fr/english/viewtop ... 209#242209Are you again sure? Which code example could you give me to prove it?Trond wrote:DisableDebugger is not enough
You are right.Trond wrote:It doesn't behave like the And in PB.
I thank you for the codes and the links.Zero is false
All the others integer values are true
Code: Select all
! CMP [Var], 0
Etc...
Code: Select all
! XOR EAX, EAX
! LEA EDI, [Var]
! SCASD
Etc...
Code: Select all
For Max = 1 To 3 Step 2
Result$ = ""
For A = 0 To Max
For B = 0 To Max
! xor eax, eax
! lea edi, [v_A]
! scasd
! je l_isfalse2
! lea edi, [v_B]
! scasd
! je l_isfalse2
IsTrue2:
Result$ + "1"
! jmp l_endif2
IsFalse2:
Result$ + "0"
EndIf2:
Next
Result$ + "-"
Next
MessageRequester("AND gate (" + Str(((Max - 1) / 2) + 1) + " bit(s) per input)", Result$)
Next
Code: Select all
DisableDebugger
timeBeginPeriod_(1)
Macro ExecutionIfTrue()
; Nothing
EndMacro
Macro ExecutionIfFalse()
; Nothing
EndMacro
Macro Test1()
If A
If B
ExecutionIfTrue()
Else
ExecutionIfFalse()
EndIf
Else
ExecutionIfFalse()
EndIf
EndMacro
Macro Test2()
If A And B
ExecutionIfTrue()
Else
ExecutionIfFalse()
EndIf
EndMacro
Macro Test3() ; (= If A And B) /!\ /!\ /!\ /!\ /!\
! xor eax, eax
! lea edi, [v_A]
! scasd
! je l_isfalse2
! lea edi, [v_B]
! scasd
! je l_isfalse2
IsTrue2:
ExecutionIfTrue()
! jmp l_endif2
IsFalse2:
ExecutionIfFalse()
EndIf2:
EndMacro ; \!/ \!/ \!/ \!/ \!/
Macro Counter(InternalMacro)
Cumul = 0
For A = 0 To 1
For B = 0 To 1
InternalMacro
Next
Next
EndMacro
Define Test1.I
Define Test2.I
Define Test3.I
Define ValeurIni.I
Define ValeurFin.I
Define Cumul.I
Define A.I = 0
Define B.I = 0
Define TotalTest.I = 10000000
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test1() )
Next
ValeurFin=timeGetTime_()
Test1=ValeurFin-ValeurIni
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test2() )
Next
ValeurFin=timeGetTime_()
Test2=ValeurFin-ValeurIni
ValeurIni=timeGetTime_()
For I = 1 To TotalTest
Counter(Test3() )
Next
ValeurFin=timeGetTime_()
Test3=ValeurFin-ValeurIni
MessageRequester("Tests without debugger", "Test #1 (If a If b) = " + Str(Test1) + " ms" + Chr(10) + "Test #2 (If a And b) = " + Str(Test2) + " ms" + Chr(10) + "Test #3 (Asm /!\ with LEA) = " + Str(Test3) + " ms")
timeEndPeriod_(1)
Interesting! The first optimization (#1) is ok but the second one is out (#3)...Michael Vogel wrote:Here are the results of the netbook cpu:
Test#1: 829ms
Test#2: 924ms
Test#3: 1082ms Shocked
XP SP3, Intel Atom N270, Kaspersky Security Suite 2009Ollivier wrote:Interesting! The first optimization (#1) is ok but the second one is out (#3)...
Excuse me but I'd like to know you which OS, which CPU and which Anti-virus have you got?
Ollivier
Using Windows XP SP3, AMD Athlon 64 3500+ 2.21GHz, ZoneAlarmTest #1 (If a If b) = 506 ms
Test #2 (If a And b) = 326 ms
Test #3 (Asm /!\ with LEA) = 212 ms