With the latest changes the performance has changed drastically. Running the above code again will result in the following output:
Code: Select all
0.15603045563281626
0.2694162790844672
Currently, the bottleneck is retrieving the view angle. If you comment out the lines that retrieve it and run the code again, you will get the following output:
Code: Select all
0.08905209688916216
0.005697254915190797
As you can see, the built-in methods are now even faster than the tweaked versions I created for you.
Edit:
This is now the fastest method:
Syntax: Select all
from timeit import Timer
ITERATIONS = 10000
result = Timer("""
player.origin
player.eye_location
player.view_angle
player.velocity
""",
"""
from players.entity import Player
player = Player(1)
""").timeit(ITERATIONS)
print(result)
# Fastest method
result = Timer("""
player.origin
player.eye_location
get_view_angle(player)
player.velocity
""",
"""
from players.entity import Player
from mathlib import QAngle
def get_eye_angle(player):
return player.get_network_property_vector('m_angEyeAngles[0]')
def get_view_angle(player):
eye_angle = get_eye_angle(player)
eye_angle_y = eye_angle.y
eye_angle_y = (eye_angle_y + 360) if eye_angle_y < 0 else eye_angle_y
return QAngle(eye_angle.x, eye_angle_y, player.rotation.z)
player = Player(1)
""").timeit(ITERATIONS)
print(result)
Running this code will print the following result:
Code: Select all
0.21171037814750093
0.026995176141468846
Comparing the initial performance (1.4469872402428336) with the fastest method (0.026995176141468846) it's now ~50 times faster.