Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
Loading...
Searching...
No Matches
async_await_demo.py
Go to the documentation of this file.
1import timeit
2
3complexity = 1000
4
5
6async def do_stuff_sync():
7 for i in range(complexity):
8 print(i)
9
10
11async def stuff_sync():
12 await do_stuff_sync()
13 await do_stuff_sync()
14
15
16# This message is printed before the do_stuff_sync() is called
17print("perf (async/await)=", timeit.timeit(stuff_sync, number=1))
18
19
21 for i in range(complexity):
22 print(i)
23
24
25def stuff():
26 do_stuff()
27 do_stuff()
28
29
30print("perf (traditional)=", timeit.timeit(stuff, number=1))