# -- coding: utf-8 -- import cProfile from decimal import Decimal import pstats a = None b = 0 c = {} left_column_width = 35 loop_range = range(20000000) def test1(): for i in loop_range: x = y = a def test2(): for i in loop_range: x = a y = a def test3(): for i in loop_range: x = y = z = a def test4(): for i in loop_range: x = a y = a z = a def test5(): for i in loop_range: x = y = b def test6(): for i in loop_range: x = b y = b def test7(): for i in loop_range: x = y = z = b def test8(): for i in loop_range: x = b y = b z = b def test9(): for i in loop_range: x = y = c def test10(): for i in loop_range: x = c y = c def test11(): for i in loop_range: x = y = z = c def test12(): for i in loop_range: x = c y = c z = c test1_profile = cProfile.Profile() test1_profile.runcall(test1) test1_profile.print_stats(sort='cumtime') test2_profile = cProfile.Profile() test2_profile.runcall(test2) test2_profile.print_stats(sort='cumtime') test3_profile = cProfile.Profile() test3_profile.runcall(test3) test3_profile.print_stats(sort='cumtime') test4_profile = cProfile.Profile() test4_profile.runcall(test4) test4_profile.print_stats(sort='cumtime') test5_profile = cProfile.Profile() test5_profile.runcall(test5) test5_profile.print_stats(sort='cumtime') test6_profile = cProfile.Profile() test6_profile.runcall(test6) test6_profile.print_stats(sort='cumtime') test7_profile = cProfile.Profile() test7_profile.runcall(test7) test7_profile.print_stats(sort='cumtime') test8_profile = cProfile.Profile() test8_profile.runcall(test8) test8_profile.print_stats(sort='cumtime') test9_profile = cProfile.Profile() test9_profile.runcall(test9) test9_profile.print_stats(sort='cumtime') test10_profile = cProfile.Profile() test10_profile.runcall(test10) test10_profile.print_stats(sort='cumtime') test11_profile = cProfile.Profile() test11_profile.runcall(test11) test11_profile.print_stats(sort='cumtime') test12_profile = cProfile.Profile() test12_profile.runcall(test12) test12_profile.print_stats(sort='cumtime') print('number of loops:'.ljust(left_column_width, ' '), len(loop_range), '\n') print("x = y = a:".ljust(left_column_width, ' '), pstats.Stats(test1_profile).total_tt) print('x = a') print("y = a:".ljust(left_column_width, ' '), pstats.Stats(test2_profile).total_tt, '\n') print("x = y = z = a:".ljust(left_column_width, ' '), pstats.Stats(test3_profile).total_tt) print('x = a') print('y = a') print("z = a:".ljust(left_column_width, ' '), pstats.Stats(test4_profile).total_tt, '\n') print("x = y = b:".ljust(left_column_width, ' '), pstats.Stats(test5_profile).total_tt) print('x = b') print("y = b:".ljust(left_column_width, ' '), pstats.Stats(test6_profile).total_tt, '\n') print("x = y = z = b:".ljust(left_column_width, ' '), pstats.Stats(test7_profile).total_tt) print('x = b') print('y = b') print("z = b:".ljust(left_column_width, ' '), pstats.Stats(test8_profile).total_tt, '\n') print("x = y = c:".ljust(left_column_width, ' '), pstats.Stats(test9_profile).total_tt) print('x = c') print("y = c:".ljust(left_column_width, ' '), pstats.Stats(test10_profile).total_tt, '\n') print("x = y = z = c:".ljust(left_column_width, ' '), pstats.Stats(test11_profile).total_tt) print('x = c') print('y = c') print("z = c:".ljust(left_column_width, ' '), pstats.Stats(test12_profile).total_tt)