# Run it using: benchmark.py script bench_bytearray.py --file=original # https://bitbucket.org/haypo/misc/src/tip/python/benchmark.py def run_benchmark(bench): bench.start_group("non regression") for length in ('10**1', '10**3', '10**5', '10**7'): bench.timeit('b=bytearray()\nfor i in loops:\n b += a\nc = bytes(b)', setup='a = b"x"; loops = range(%s)' % length, name="concatenate %s bytes" % length) bench.start_group("deleting front, append tail") for length in ('10**1', '10**3', '10**5', '10**7'): bench.timeit("b[:100] = b''; b.extend(s)", setup="b=bytearray(%s); s=b'x'*100" % length, name="buffer %s bytes" % length)