# -- coding: utf-8 -- import cProfile import pstats left_column_width = 30 loop_range = range(1000000) class SuperA: def __init__(self): super().__init__() self.a = None class SuperB: def __init__(self): super().__init__() self.b = 0 class SuperC: def __init__(self): super().__init__() self.c = {} class SuperD(SuperA, SuperB): def __init__(self): super().__init__() self.d = None class SuperE(SuperB, SuperC): def __init__(self): super().__init__() self.e = 1 class SuperF(SuperD, SuperC): def __init__(self): super().__init__() self.f = 'Test' class SuperG(SuperE, SuperF): def __init__(self): super().__init__() self.g = [] class NotSuperA: def __init__(self): object.__init__(self) self.a = None class NotSuperB: def __init__(self): object.__init__(self) self.b = 0 class NotSuperC: def __init__(self): object.__init__(self) self.c = {} class NotSuperD(NotSuperA, NotSuperB): def __init__(self): NotSuperA.__init__(self) NotSuperB.__init__(self) self.d = None class NotSuperE(NotSuperB, NotSuperC): def __init__(self): NotSuperC.__init__(self) NotSuperB.__init__(self) self.e = 1 class NotSuperF(NotSuperD, NotSuperC): def __init__(self): NotSuperD.__init__(self) NotSuperC.__init__(self) self.f = 'Test' class NotSuperG(NotSuperE, NotSuperF): def __init__(self): NotSuperE.__init__(self) NotSuperF.__init__(self) self.g = [] def test1(): for i in loop_range: x = SuperD() def test2(): for i in loop_range: x = SuperE() def test3(): for i in loop_range: x = SuperF() def test4(): for i in loop_range: x = SuperG() def test5(): for i in loop_range: x = NotSuperD() def test6(): for i in loop_range: x = NotSuperE() def test7(): for i in loop_range: x = NotSuperF() def test8(): for i in loop_range: x = NotSuperG() 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') print('number of loops:'.ljust(left_column_width, ' '), len(loop_range), '\n') print("SuperD():".ljust(left_column_width, ' '), pstats.Stats(test1_profile).total_tt) print("SuperE():".ljust(left_column_width, ' '), pstats.Stats(test2_profile).total_tt) print("SuperF():".ljust(left_column_width, ' '), pstats.Stats(test3_profile).total_tt) print("SuperG():".ljust(left_column_width, ' '), pstats.Stats(test4_profile).total_tt, '\n') print("NotSuperD():".ljust(left_column_width, ' '), pstats.Stats(test5_profile).total_tt) print("NotSuperE():".ljust(left_column_width, ' '), pstats.Stats(test6_profile).total_tt) print("NotSuperF():".ljust(left_column_width, ' '), pstats.Stats(test7_profile).total_tt) print("NotSuperG():".ljust(left_column_width, ' '), pstats.Stats(test8_profile).total_tt, '\n') print('SuperG', SuperG().__dict__) print('NotSuperG', NotSuperG().__dict__)