import perf import marshal with open('./Lib/logging/__init__.py') as f: source = f.read() code = compile(source, '__init__.py', 'exec') def bm_marshal(): marshal.dumps(code) def bm_compile(): marshal.dumps(compile(source, '__init__.py', 'exec')) runner = perf.Runner() runner.bench_func('marshal', bm_marshal) runner.bench_func('compile+marshal', bm_compile)