Source

blaag.haard.se / code / constants / testhack.py

Full commit
from inlining import *
from timer import Timer


def rate(times = 100000):
    
    src = open('benchmark.py').read()
    non_transformed_ns = {}
    exec(compile(src, 'non_transformed', 'exec'), non_transformed_ns)

    transformed_ns = {}
    exec(compile(transform(src), 'transformed', 'exec'), transformed_ns)
    
    with Timer() as ni_timer:
        non_transformed_ns['costly'](times)
    print('Non-transformed  (millisecs): %.2f' % ni_timer.elapsed_ms)

    with Timer() as i_timer:
        transformed_ns['costly'](times)
    print('Transformed  (millisecs): %.2f' % i_timer.elapsed_ms)

    print('Difference: %.2f%%' % ((ni_timer.elapsed_ms-i_timer.elapsed_ms)/ni_timer.elapsed_ms*100))
    
if __name__ == "__main__":
    rate()