-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench1.py
62 lines (48 loc) · 1.44 KB
/
bench1.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
import fake_ast
import ast
import sys
ast.AST = fake_ast.AST
dump = ast.dump
import timeit
from glob import glob
try:
path = sys.argv[1]
except IndexError:
path = "../cpython/Lib/**/*.py"
files = {}
for path in glob(path):
try:
txt = open(path, 'r').read()
except UnicodeDecodeError:
continue
# try:
# if py_ast.dump(py_ast.parse(txt)) != py_ast.dump(rust_ast.parse(txt)):
# continue
# except SyntaxError:
# continue
files[path] = txt
t = [0.0] * 5
import ast as py_ast
import baembal as rust_ast
REPEAT = 5
def f(i):
return f'{t[i]/t[0]:.2f}({t[i]:.2f}s)'
for path, txt in files.items():
# p = py_ast.parse(txt)
# r = rust_ast.parse(txt)
# compile(p, 'x', 'exec')
# compile(r, 'x', 'exec')
# print('starting', path)
# break
try:
p = timeit.timeit(lambda: (py_ast.parse(txt)), number=REPEAT)
r1 = timeit.timeit(lambda: (rust_ast.parse(txt, locate=False)), number=REPEAT)
r2 = timeit.timeit(lambda: (rust_ast.parse(txt, locate=True)), number=REPEAT)
r3 = timeit.timeit(lambda: (rust_ast.parse_wrap(txt, locate=False)), number=REPEAT)
r4 = timeit.timeit(lambda: (rust_ast.parse_wrap(txt, locate=True)), number=REPEAT)
except Exception as e:
print('error:', path, e)
continue
for i, d in enumerate([p, r1, r2, r3, r4]):
t[i] += d
print('acc:', f(0), f(1), f(2), f(3), f(4), path)