Last active
January 20, 2022 07:33
-
-
Save hqshi/d888cde875263552ade60e6a67716ec8 to your computer and use it in GitHub Desktop.
test_code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
by_classmethod = """ | |
class Test: | |
def a(self): | |
for i in range(0, 100): | |
x = 2 ** 10 | |
def __call__(self): | |
self.a() | |
t = Test() | |
for i in range(0, 100): | |
t() | |
""" | |
by_staticmethod = """ | |
class Test: | |
@staticmethod | |
def a(): | |
for i in range(0, 100): | |
x = 2 ** 10 | |
def __call__(self): | |
Test.a() | |
t = Test() | |
for i in range(0, 100): | |
t() | |
""" | |
print(timeit.timeit(by_classmethod, number=10**4)) | |
print(timeit.timeit(by_staticmethod, number=10**4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment