""" Micro-benchmark for the Python memory allocator. 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): bench.timeit('object()') for length in ('10', '10**3', '10**6'): bench.timeit("char * %s" % length, setup="char = b'A'", name="b'A' * %s" % length) for length in ('10', '10**3', '10**6', '10**8'): bench.timeit("char * %s" % length, setup="char = 'A'", name="'A' * %s" % length) for length in ('10**%s' % i for i in range(9)): bench.timeit('one_none * %s' % length, setup='one_none = (None,)', name='(None,) * %s' % length) for length in ('10', '10**3', '10**6', '10**8'): bench.timeit('large_list[1:-1]', setup='large_list = [None] * %s' % length, name='([None] * %s)[1:-1]' % length) for length in ('10', '10**3', '10**6', '10**8'): bench.timeit('bytes(%s)' % length) for length in ('10', '10**3', '10**6', '10**8'): bench.timeit('bytearray(%s)' % length)