""" Micro-benchmark for the Python fast call. Run it with: ./python.orig benchmark.py script bench_fast.py --file=orig ./python.patched benchmark.py script bench_fast.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("list(filter(f, s))", "f = lambda x: x; s = list(range(1000))", "filter(lambda x: x, range(1000))") bench.timeit("list(map(f, s))", "f = lambda x: x; s = list(range(1000))", "map(lambda x: x, range(1000))") bench.timeit("list(map(f, s, s))", "f = lambda x, y: x+y; s = list(range(1000))", "map(lambda x, y: x+y, range(1000), range(1000))") bench.timeit("sorted(s, key=f)", "f = lambda x: x; s = list(range(1000))", "sorted(list, key=lambda x: x)") bench.timeit("sorted(s)", "s = list(range(1000))", "sorted(list)")