""" 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 error_handler in ('ignore', 'replace', 'surrogateescape', 'backslashreplace'): bench.start_group(error_handler) for length in ('10**1', '10**3', '10**2', '10**4'): bench.timeit(setup='data = bytes(range(256)) * %s' % length, stmt='data.decode("ascii", "%s")' % error_handler, name='256 x %s bytes' % length)