-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
65 lines (56 loc) · 1.22 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import timeit
def benchmark_lexer():
setup = """
from rasper_ducky.duckyscript.preprocessor import Preprocessor
from rasper_ducky.duckyscript.lexer import Lexer
"""
stmt = """
code = '''
RD_KBD WIN FR
DEFINE #COUNT 3
FUNCTION open_powershell()
GUI R
STRINGLN powershell
END_FUNCTION
FUNCTION hello_world()
$x = 0
WHILE ($x < #COUNT)
DELAY 500
STRING Hello, World!
SPACE
$x = $x + 1
END_WHILE
END_FUNCTION
open_powershell()
DELAY 1000
hello_world()
IF TRUE THEN
IF FALSE THEN
STRING A
ELSE
IF TRUE THEN
STRING B
ELSE
STRING C
END_IF
END_IF
END_IF
DELAY 10
VAR $x = 10
STRINGLN Hello, World!
FUNCTION f(x)
STRING Coucou
END_FUNCTION
WHILE TRUE
STRING Hello
END_WHILE
'''
preprocessor = Preprocessor()
code = preprocessor.process(code)
lexer = Lexer(code)
tokens = list(lexer.tokenize())
"""
iterations = 10000
result = timeit.timeit(stmt, setup, number=iterations)
print(f"Average time per run: {result/iterations:.6f} seconds")
benchmark_lexer()