Skip to content

Commit 66cd79d

Browse files
committed
decorator
1 parent 8d1c884 commit 66cd79d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import random
2+
import time
3+
4+
5+
def benchmark(func):
6+
def wrapper(*args, **kwargs):
7+
t = time.perf_counter()
8+
res = func(*args, **kwargs)
9+
print(f"{func.__name__} {time.perf_counter()-t}")
10+
return res
11+
return wrapper
12+
13+
@benchmark
14+
def random_tree(n):
15+
temp = [n for n in range(n)]
16+
for i in range(n+1):
17+
temp[random.choice(temp)] = random.choice(temp)
18+
return temp
19+
20+
21+
if __name__ == '__main__':
22+
random_tree(10000)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class A(object):
2+
def foo(self, x):
3+
print(f"foo({self}, {x}) 실행")
4+
5+
@classmethod
6+
def class_foo(cls, x):
7+
print(f"class_foo({cls}, {x}) 실행")
8+
9+
@staticmethod
10+
def static_foo(x):
11+
print(f"static_foo({x}) 실행")
12+
13+
if __name__ == '__main__':
14+
a = A()
15+
a.foo(1)
16+
a.class_foo(2)
17+
A.class_foo(2)
18+
a.static_foo(3)
19+
A.static_foo(3)

0 commit comments

Comments
 (0)