Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc244dc1

Browse files
committed
updates
1 parentffbb005 commitc244dc1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎06_execution_time.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
ExecutionTime
3+
4+
This class is used for timing execution of code.
5+
6+
For example:
7+
8+
timer = ExecutionTime()
9+
print 'Hello world!'
10+
print 'Finished in {} seconds.'.format(timer.duration())
11+
12+
"""
13+
14+
15+
importtime
16+
17+
18+
classExecutionTime:
19+
def__init__(self):
20+
self.start_time=time.time()
21+
22+
defduration(self):
23+
returntime.time()-self.start_time
24+
25+
26+
# ---- run code ---- #
27+
28+
importrandom
29+
30+
timer=ExecutionTime()
31+
sample_list=list()
32+
my_list= [random.randint(1,888898)fornuminxrange(1,1000000)ifnum%2==0]
33+
print'Finished in {} seconds.'.format(timer.duration())

‎readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
1.**03_simple_twitter_manager.py**: accessing the Twitter API, example functions
66
3.**04_rename_with_slice.py**: rename group of files, within a single directory, using slice
77
4.**05_load_json_without_dupes.py**: load json, convert to dict, raise error if there is a duplicate key
8+
5.**06_execution_time.py**: class used for timing execution of code

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp