""" Micro-benchmark for the Python. 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 """ LENGTHS = ('10', '100', '10**3', '10**5') def run_benchmark(bench): bench.start_group('without spaces') for n in LENGTHS: bench.timeit(setup='data = "AB" * %s' % n, stmt='bytes.fromhex(data)') bench.start_group('with 0.5 space') for n in LENGTHS: bench.timeit(setup='data = "ABAB " * (%s // 2)' % n, stmt='bytes.fromhex(data)') bench.start_group('with 1 space') for n in LENGTHS: bench.timeit(setup='data = "AB " * %s' % n, stmt='bytes.fromhex(data)')