-
Notifications
You must be signed in to change notification settings - Fork 0
/
timing.py
29 lines (22 loc) · 941 Bytes
/
timing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
# Define the fields in timingObj
fields = ["updateGameState", "renderPlayers", "renderPowerUps", "handleMovement"]
# Initialize counters for each field
counters = {field: 0 for field in fields}
timers = {field: 0 for field in fields}
# Open the file in read mode
with open("./logs/timingLog1.txt", "r") as logs:
for line in logs:
# Load the JSON data from the line
timingObj = json.loads(line.strip())
# Update the counters and timers for each field
for field in fields:
counters[field] += 1
timers[field] += timingObj[field]
# Calculate the average time for each field
averages = {field: timers[field] / counters[field] for field in fields}
with open("./logs/timingAverages1.txt", "a") as logs:
logs.write(json.dumps(averages) + '\n')
# Print the average times
# for field, average in averages.items():
# print(f"{field}: {average}")