-
Notifications
You must be signed in to change notification settings - Fork 39
/
benchmark.py
46 lines (40 loc) · 1.11 KB
/
benchmark.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
import time
from TagScriptEngine import Verb, Interpreter, block, adapter
blocks = [
block.MathBlock(),
block.RandomBlock(),
block.RangeBlock(),
block.StrfBlock(),
block.AssignmentBlock(),
block.FiftyFiftyBlock(),
block.LooseVariableGetterBlock()
]
x = Interpreter(blocks)
# data to inject
dummy = {
"message": adapter.StringAdapter("Hello, this is my message.")
}
def timerfunc(func):
"""
A timer decorator
"""
def function_timer(*args, **kwargs):
"""
A nested function for timing other functions
"""
start = time.time()
value = func(*args, **kwargs)
end = time.time()
runtime = end - start
msg = "The runtime for {func} took {time} seconds to complete 1000 times"
print(msg.format(func=func.__name__,
time=runtime))
return value
return function_timer
@timerfunc
def v2_test():
for i in range(1000):
x.process("{message} {#:1,2,3,4,5,6,7,8,9,10} {range:1-9} {#:1,2,3,4,5} {message} {strf:Its %A}", dummy)
if __name__ == '__main__':
v2_test()