Performance Analyse

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

Silver_Knee

Betreff: Performance Analyse

BeitragMi, Apr 15, 2015 19:00
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey, ich versuche gerade ein Stück code zu analysieren.

Er wird in der Hauptschleife ausgeführt und unter Umständen sieht es nicht sehr rosig aus:

Code: [AUSKLAPPEN]
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 170
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 257--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 1
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 166
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 181--
DebugLog:Mem: 5715712
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 163
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 170--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 164
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 258--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 6
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 6 frames
DebugLog:Collisions: 167
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 1102--
DebugLog:Mem: 5715680
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 166
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 277--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 164
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 205--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 6
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 6 frames
DebugLog:Collisions: 165
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 517--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 166
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 300--
DebugLog:Mem: 5715664
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 164
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 4149--
DebugLog:Mem: 5715680
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 166
DebugLog:Send Update: 0
DebugLog:--END PHYSICS: 256--
DebugLog:Mem: 5715712
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 8 ms 7 frames
DebugLog:Collisions: 163
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 212--
DebugLog:Mem: 5715664


Die Teile "Player movement", "Physics", "Collisions" und "Send Updates" sind dabei fast alle Teile des Codes. Die Zeit addiert sich allerdings teilweise nicht auf. Ich zeig das mal:

Hauptschleife
BlitzMax: [AUSKLAPPEN]
	If TGame._instance And TGame._instance._selectedShip
DebugLog "--BEGIN PHYSICS--"
time=MilliSecs() & $7fFFffFF
Physics()
DebugLog "--END PHYSICS: "+(MilliSecs() & $7fFFffFF-time)+"--"
EndIf


Phyiscs:
BlitzMax: [AUSKLAPPEN]
Function Physics()
TPhysics.instance.Physics()
End Function

Type TPhysics
Global instance:TPhysics = New TPhysics

Field updateTime:Int
Field game:TGame

Method Physics()
Local ms:Int=MilliSecs() & $7fFFffFF

Local frames:Byte = (ms - updateTime) / 30
DebugLog "Frames: "+frames
If frames > 0
updateTime:+30*frames;

'debug
Local time:Int = MilliSecs()
'planet.TurnEntity 0,Double(frames)*0,00000597371:Double,0

_MoveSelectedShip(frames)

'to calculate real speed after collisions
Local oldx:Float = game._selectedShip.EntityX()
Local oldy:Float = game._selectedShip.EntityY()
Local oldz:Float = game._selectedShip.EntityZ()
DebugLog "Player movement: "+(MilliSecs()-time)

time=MilliSecs()
For Local ex:TExEntity = EachIn TExEntity.map.Values()
ex.TranslateEntity ex.sx*frames , ex.sy*frames , ex.sz*frames

'TODO: DANGEROUS
Local radius:Float

If TShip(ex)
If TOwnShip(ex) And TOwnShip(ex).sector.Compare(game._selectedShip.sector)<>0
radius = 0
Else
radius = TShip(ex)._kind.radius*30
EndIf
Else
radius = 2000
EndIf

If radius=0 Or ex.__entity.EntityDistance(game._selectedShip.__entity) > radius
ex.HideEntity()
Else
ex.ShowEntity()
EndIf
'End Rem

If TShip(ex)
_HandleActivities(TShip(ex))
EndIf
Next

DebugLog "Physics: " + (MilliSecs() - time ) + " ms "+ frames +" frames"

time=MilliSecs()
UpdateWorld

game._selectedShip.sx=(game._selectedShip.EntityX()-oldx)/frames
game._selectedShip.sy=(game._selectedShip.EntityY()-oldy)/frames
game._selectedShip.sz=(game._selectedShip.EntityZ()-oldz)/frames

_HandleCollisions()
DebugLog "Collisions: "+ (MilliSecs() - time)


time=MilliSecs()
TGame._instance.SendPlayerUpdate()
DebugLog "Send Update: "+ (MilliSecs() - time)
EndIf
End Method

...


Ich habe also mit den time=Millisecs() und Debuglog "..."+(Millisecs() - time) eigentlich alles eingeklammert. Die Funktionsaufrufe und das eine If sollen zusammen mal vielleicht eine Millisekunde dauern. Von mir aus 10 aber da gibt es Runden in der Hauptschleife wie diese:
Code: [AUSKLAPPEN]
DebugLog:--BEGIN PHYSICS--
DebugLog:Frames: 7
DebugLog:Player movement: 0
DebugLog:Physics: 6 ms 7 frames
DebugLog:Collisions: 164
DebugLog:Send Update: 1
DebugLog:--END PHYSICS: 4149--


Ich mein 171 ms in der Hauptschleife sind eh schon zu viel, aber wo kamen 3 Sekunden her, die da nicht geloggt wurden?

Silver_Knee

BeitragMi, Apr 15, 2015 19:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Punkt vor Strich....

http://en.wikibooks.org/wiki/B...xpressions

Code: [AUSKLAPPEN]
DebugLog "--END PHYSICS: "+(MilliSecs() & $7fFFffFF-time)+"--"


Da wird - vor & gerechnet und das gibt ein ergebnis das manchmal relativ gut passt.
Es müsste heißen:

Code: [AUSKLAPPEN]
DebugLog "--END PHYSICS: "+((MilliSecs() & $7fFFffFF)-time)+"--"


Manchmal sieht man das erst nachdem man einen Thread auf gemacht hat Very Happy

DAK

BeitragDo, Apr 16, 2015 9:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Hehe^^ Wofür hast du das Vorzeichenwegtrimmen überhaupt drin? Das Vorzeichen sollte an dieser Stelle eigentlich egal sein, wegen dem Zweierkomplement.
Gewinner der 6. und der 68. BlitzCodeCompo

Silver_Knee

BeitragDo, Apr 16, 2015 16:56
Antworten mit Zitat
Benutzer-Profile anzeigen
ja, richtig. Hab allerdings an einer Stelle eine time für was anderes verwendet und das dann überall hinkopiert.

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group