1
2
3
4
5
|
import
time
def sayHi():
time.sleep(
1
)
print
'Hello, I am xpleaf.'
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
程序代码:
import
time
def sayHi():
start = time.time()
time.sleep(
1
)
print
'Hello, I am xpleaf.'
end = time.time()
print
'This project costs:'
,end - start
sayHi()
执行情况:
xpleaf@xpleaf-machine:/mnt/hgfs/Python/day4/blog$ python wraper.py
Hello, I am xpleaf.
This project costs:
1.00269603729
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import
time
def sayHi():
time.sleep(
1
)
print
'Hello, I am xpleaf.'
def time_counter():
start = time.time()
sayHi()
end = time.time()
print
'The project costs:'
, end - start
time_counter()
|
1
2
3
|
xpleaf@xpleaf-machine:/mnt/hgfs/Python/day4/blog$ python wraper.py
Hello, I am xpleaf.
The project costs:
1.00348091125
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import
time
def time_counter(func):
def wrapper():
start = time.time()
func()
end = time.time()
print
'The project costs:'
, end - start
return
wrapper
@time_counter
def sayHi():
time.sleep(
1
)
print
'Hello, I am xpleaf.'
sayHi()
|
1
2
3
|
xpleaf@xpleaf-machine:/mnt/hgfs/Python/day4/blog$ python wraper.py
Hello, I am xpleaf.
The project costs:
1.00221300125
|
1
2
3
|
xpleaf@xpleaf-machine:/mnt/hgfs/Python/day4/blog$ python wraper.py
Hello, I am xpleaf.
The project costs:
1.00514888763
|
1
2
3
|
xpleaf@xpleaf-machine:/mnt/hgfs/Python/day4/blog$ python wraper.py
Hello, I am xpleaf.
The project costs:
1.00514888763
|