# 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): for length in ('10**1', '10**3', '10**5', '10**7'): bench.timeit('b=bytearray()\nfor i in loops:\n b += a', setup='a = b"x"; loops = range(%s)' % length, name="%s bytes" % length)