Da wir jetzt mittlerweile in diesem Thread immer mehr verrückte Tests machen, dann lasst uns doch gleich mal den von PB generierten ASM-Code begutachten:
Code: Alles auswählen
;========= Goto Version 1 =========
; i = 0
MOV qword [v_i],0
; top1:
l_top1:
; If i < maxx
MOV r15,qword [v_i]
CMP r15,qword [v_maxx]
JGE _EndIf2
; DoSomething()
; i + 1
MOV r15,qword [v_i]
INC r15
MOV qword [v_i],r15
; Goto top1
JMP l_top1
; EndIf
_EndIf2:
;========= Goto Version 2 =========
; i = 0
MOV qword [v_i],0
; top2:
l_top2:
; If i = maxx
MOV r15,qword [v_i]
CMP r15,qword [v_maxx]
JNE _EndIf4
; Goto ende2
JMP l_ende2
; EndIf
_EndIf4:
; DoSomething()
; i + 1
MOV r15,qword [v_i]
INC r15
MOV qword [v_i],r15
; Goto top2
JMP l_top2
; ende2:
l_ende2:
;========= For-Schleife =========
; For i = 0 To maxx - 1
MOV qword [v_i],0
_For5:
MOV r15,qword [v_maxx]
DEC r15
CMP r15,qword [v_i]
JL _Next6
; DoSomething()
; Next
_NextContinue6:
INC qword [v_i]
JNO _For5
_Next6:
;========= While-Schleife =========
; i = 0
MOV qword [v_i],0
; While i < maxx
_While7:
MOV r15,qword [v_i]
CMP r15,qword [v_maxx]
JGE _Wend7
; DoSomething()
; i + 1
MOV r15,qword [v_i]
INC r15
MOV qword [v_i],r15
; Wend
JMP _While7
_Wend7:
;========= Repeat-Schleife =========
; i = 0
MOV qword [v_i],0
; Repeat
_Repeat8:
; DoSomething()
; i + 1
MOV r15,qword [v_i]
INC r15
MOV qword [v_i],r15
; Until i = maxx
MOV r15,qword [v_i]
CMP r15,qword [v_maxx]
JNE _Repeat8
_Until8:
Man sieht jetzt, dass im Grunde jede Schleife das selbe macht, außer die For-Next-Schleife.
Bei alle Schleifen wird 'i' so inkrementiert:
Außer bei der For-Schleife. Da wird nur das hier gemacht:
Das könnte der Unterschied sein, den ich deutlich in den Zeiten sehen kann, wenn ich das Macro 'DoSomething()' komplett leere:
maxx = 400000000 hat geschrieben:Goto Version 1: 1136
Goto Version 2: 1082
For Next: 879
While Wend: 1088
Repeat Until: 1143