Created
January 13, 2026 20:44
-
-
Save lega911/166954a6e74b213b717a4c4166184d59 to your computer and use it in GitHub Desktop.
switch test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # taskset 0x00000001 python3 ./async.py | |
| import asyncio | |
| import time | |
| value = 0 | |
| COUNT = 200_000_000 | |
| def count(): | |
| global value | |
| value += 1 | |
| async def acount(): | |
| global value | |
| value += 1 | |
| async def loop(): | |
| for _ in range(100): | |
| count() | |
| async def main(): | |
| start = time.time() | |
| while value < COUNT: | |
| await loop() | |
| # await acount() | |
| print(value, time.time() - start) | |
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # taskset 0x00000001 python3 ./sync.py & x 8 | |
| import time | |
| start = time.time() | |
| value = 0 | |
| COUNT = 200_000_000 // 8 | |
| # COUNT = 200_000_000 | |
| def count(): | |
| global value | |
| value += 1 | |
| def loop(): | |
| for _ in range(COUNT): | |
| count() | |
| loop() | |
| print(value, time.time() - start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment