forked from phenom4n4n/TagScript
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.py
More file actions
51 lines (40 loc) · 1.14 KB
/
benchmark.py
File metadata and controls
51 lines (40 loc) · 1.14 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
from typing import Callable
from bTagScript import Interpreter, adapter, block
blocks = [
block.MathBlock(),
block.RandomBlock(),
block.RangeBlock(),
block.StrfBlock(),
block.VarBlock(),
block.LooseVariableGetterBlock(),
]
x = Interpreter(blocks)
dummy = {"message": adapter.StringAdapter("Hello, this is my message.")}
def timerfunc(func: Callable) -> Callable:
"""
A timer decorator
"""
def function_timer(*args, **kwargs) -> None:
"""
A nested function for timing other functions
"""
start = time.time()
value = func(*args, **kwargs)
end = time.time()
runtime = end - start
print(f"The runtime for {func.__name__} took {runtime} seconds to complete 1,000 times")
return value
return function_timer
@timerfunc
def v2_test() -> None:
"""
V2 Testing benchmarks
"""
for _ in range(1000):
x.process(
r"{message} {#:1,2,3,4,5,6,7,8,9,10} {range:1-9} {=(variablename):Hello World} {variablename} {message} {strf:Its %A}",
dummy,
)
if __name__ == "__main__":
v2_test()