File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ import time
2
+ import asyncio
3
+
4
+ async def hellworld (sleep_time ):
5
+ print ('hellworld starts, then sleep for %s seconds' % sleep_time )
6
+ await asyncio .sleep (sleep_time )
7
+ print ('hellworld ends, after sleep: %s seconds' % sleep_time )
8
+
9
+ loop = asyncio .get_event_loop ()
10
+
11
+ start = time .time ()
12
+ loop .run_until_complete (asyncio .gather (hellworld (1 ), hellworld (2 )))
13
+ print ("Running program takes: %s seconds" % (time .time () - start ))
Original file line number Diff line number Diff line change
1
+ import time
2
+
3
+ def hellworld (sleep_time ):
4
+ print ('hellworld starts, then sleep for %s seconds' % sleep_time )
5
+ time .sleep (sleep_time )
6
+ print ('hellworld ends, after sleep: %s seconds' % sleep_time )
7
+
8
+ start = time .time ()
9
+ hellworld (1 )
10
+ hellworld (2 )
11
+ print ("Running program takes: %s seconds" % (time .time () - start ))
You can’t perform that action at this time.
0 commit comments