Skip to content

Instantly share code, notes, and snippets.

@hqshi
Last active January 20, 2022 07:33
Show Gist options
  • Save hqshi/d888cde875263552ade60e6a67716ec8 to your computer and use it in GitHub Desktop.
Save hqshi/d888cde875263552ade60e6a67716ec8 to your computer and use it in GitHub Desktop.
test_code
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