Skip to content

Commit a1f2ab8

Browse files
committed
add utils package
1 parent 0a3bb9d commit a1f2ab8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

util/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Created by imoyao at 2019/5/14 14:16
4+
import os
5+
import sys
6+
7+
currpath = os.path.join(os.getcwd(), os.path.dirname(__file__))
8+
if currpath not in sys.path:
9+
sys.path.append(currpath)
10+
11+
from . import utils

util/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Created by imoyao at 2019/5/14 14:16
4+
import time
5+
6+
7+
def show_time(func):
8+
def wrap_func(*args, **kwargs):
9+
start_time = time.time()
10+
ret_result = func(*args, **kwargs)
11+
end_time = time.time()
12+
print('The function **{0}** takes {1} time.'.format(func.__name__, end_time - start_time))
13+
return ret_result
14+
15+
return wrap_func
16+
17+
18+
@show_time
19+
def foo(n):
20+
for _ in list(range(n)):
21+
pass
22+
23+
24+
if __name__ == '__main__':
25+
26+
foo(100)

0 commit comments

Comments
 (0)