""" Micro-benchmark for the Python ASCII decoder. Run it with: ./python.orig benchmark.py script bench_str.py --file=orig ./python.patched benchmark.py script bench_str.py --file=patched ./python.patched benchmark.py compare_to orig patched Download benchmark.py from: https://bitbucket.org/haypo/misc/raw/tip/python/benchmark.py """ def run_benchmark(bench): for encoding in ('ascii', 'latin1'): bench.start_group(encoding) for length in ('10**1', '10**3', '10**2', '10**4'): bench.timeit(setup=r'data = ("\udcff" * 99 + "a") * %s' % length, stmt='data.encode("%s", "surrogateescape")' % encoding, name='100 x %s characters' % length)