39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""vast_c vs vast 性能基准(临时脚本)"""
|
|
import sys
|
|
import time
|
|
|
|
sys.path.insert(0, r'd:\Users\TermiNexus\Desktop\TransPyC')
|
|
sys.path.insert(0, r'd:\Users\TermiNexus\Desktop\TransPyC\lib')
|
|
|
|
import vast
|
|
import vast_c
|
|
|
|
Parts = []
|
|
for I in range(30):
|
|
Parts.append(f'def Func{I}(A: int, B: float = 1.5) -> str:')
|
|
Parts.append(' X = A + B * 2')
|
|
Parts.append(' if X > 10:')
|
|
Parts.append(' return "big"')
|
|
Parts.append(' else:')
|
|
Parts.append(' return "small"')
|
|
Parts.append(f'class Klass{I}:')
|
|
Parts.append(' def __init__(self):')
|
|
Parts.append(' self.Items = [I for I in range(10) if I % 2 == 0]')
|
|
Parts.append(' def Run(self):')
|
|
Parts.append(' return self.Items[0] if self.Items else None')
|
|
Src = '\n'.join(Parts)
|
|
N = 50
|
|
|
|
T0 = time.perf_counter()
|
|
for _ in range(N):
|
|
vast.parse(Src)
|
|
T1 = time.perf_counter()
|
|
for _ in range(N):
|
|
vast_c.parse(Src)
|
|
T2 = time.perf_counter()
|
|
Va = (T1 - T0) / N * 1000
|
|
Vc = (T2 - T1) / N * 1000
|
|
print(f'vast : {Va:.3f} ms/次')
|
|
print(f'vast_c : {Vc:.3f} ms/次')
|
|
print(f'加速比 : {Va / Vc:.1f}x')
|