
    'i                     f    d Z ddlZddlmZ ddlmZ  eed      Z G d dej
                        Zy)	zUTests to show that the benchmarks we based our speed optimizations on are
still valid    N)partial)timeiti  )numberc                       e Zd Zd Zd Zd Zy)TestBenchmarksc                 h    t        dd      }t        dd      }| j                  ||k  |d|       y)z4See what's faster at int key lookup: dicts or lists.zitem = l[9000]zl = [0] * 10000zitem = d[9000]z d = {x: 0 for x in range(10000)}z < Nr   
assertTrue)self	list_time	dict_times      S/var/www/br/venv/lib/python3.12/site-packages/parsimonious/tests/test_benchmarks.pytest_lists_vs_dictsz"TestBenchmarks.test_lists_vs_dicts
   s8    +->?	+-OP	 		I-Iy/QR    c                 j    t        dd      }t        dd      }| j                  ||k  |d|d       y)zHow bad is the calling penalty?z	l[0] += 1zl = [0]zadd(); l[0] += 1zl = [0]
def add():
    passz (no call) < z (call)Nr	   )r   no_callcalls      r   test_call_vs_inlinez"TestBenchmarks.test_call_vs_inline   s9    i0( +5 6 	$gt(TUr   c                 j    t        dd      }t        dd      }| j                  ||k  |d|d       y)z;Can I beat the speed of regexes by special-casing literals?zr.match(t, 19)zEimport re
r = re.compile('hello')
t = 'this is the finest hello ever'zt.startswith('hello', 19)z#t = 'this is the finest hello ever'z (startswith) < z (re)Nr	   )r   re_timestartswith_times      r   test_startswith_vs_regexz'TestBenchmarks.test_startswith_vs_regex   sE    23
 !!<!FH 	'1+:GD	Fr   N)__name__
__module____qualname__r   r   r    r   r   r   r   	   s    S	VFr   r   )__doc__unittest	functoolsr   r   TestCaser   r   r   r   <module>r!      s3      		'"FX&& "Fr   