Created
December 2, 2023 19:22
-
-
Save Gouvernathor/f9e15451788376c60bc5a3f784059baf to your computer and use it in GitHub Desktop.
Platform for measuring performance between legacy and reimplemented signature types in renpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import renpy # type: ignore | |
"""renpy | |
init python: | |
""" | |
from timeit import Timer | |
# import parameterinfo # type: ignore | |
# parameterinfo.renpy = renpy | |
def timit(): | |
ParameterInfo = renpy.ast.ParameterInfo | |
new = "Signature" in ParameterInfo.__name__ | |
if new: | |
Parameter = renpy.ast.Parameter | |
pi = ParameterInfo(( | |
Parameter("a", kind=Parameter.POSITIONAL_OR_KEYWORD, default=Parameter.empty), | |
Parameter("b", kind=Parameter.POSITIONAL_OR_KEYWORD, default="1"), | |
)) | |
t1 = Timer(''' | |
ParameterInfo(( | |
Parameter("a", kind=Parameter.POSITIONAL_OR_KEYWORD, default=Parameter.empty), | |
Parameter("b", kind=Parameter.POSITIONAL_OR_KEYWORD, default="1"), | |
)) | |
'''.strip().replace("\n", ""), | |
globals=dict(ParameterInfo=ParameterInfo, Parameter=Parameter), | |
).autorange() | |
print("new normal constructor time :", t1) | |
assert pi == ParameterInfo.legacy([("a", None), ("b", "1")], (), None, None) | |
t1 = Timer('ParameterInfo.legacy([("a", None), ("b", "1")], (), None, None)', globals=dict(ParameterInfo=ParameterInfo)).autorange() | |
print("legacy constructor time :", t1) | |
else: | |
pi = ParameterInfo([("a", None), ("b", "1")], (), None, None) | |
t1 = Timer('ParameterInfo([("a", None), ("b", "1")], (), None, None)', globals=dict(ParameterInfo=ParameterInfo)).autorange() | |
print("old normal constructor time :", t1) | |
if new: | |
t2 = Timer("pi.apply((1,), kwargs)", globals=dict(pi=pi, kwargs=dict(b=16))).autorange() | |
print("new apply time :", t2) | |
else: | |
t2 = Timer("pi.apply((1,), kwargs)", globals=dict(pi=pi, kwargs=dict(b=16))).autorange() | |
print("old apply time :", t2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment