# -- coding: utf-8 -- import cProfile import pstats left_column_width = 60 loop_range = range(5000000) class StaticA: @staticmethod def test(a): return a class NotStaticA: def test(self, a): return a def test1(): for i in loop_range: x = StaticA().test(i) def test2(): for i in loop_range: x = NotStaticA().test(i) 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') print('number of loops:'.ljust(left_column_width, ' '), len(loop_range), '\n') print("StaticA().test(i):".ljust(left_column_width, ' '), pstats.Stats(test1_profile).total_tt) print("NotStaticA().test(i):".ljust(left_column_width, ' '), pstats.Stats(test2_profile).total_tt, '\n')