Code: Select all
import time
import uasyncio as asyncio
async def ret(arg):
return arg
async def test3(count=10000, d=False):
for n in range(count):
if d:
v = dict() # list() or object()
else:
v = 0 # True 0.0 int() str()
await ret(v)
t = time.ticks_ms()
asyncio.run(test3(d=True))
print('dict(): ' + str(time.ticks_diff(time.ticks_ms(), t)))
t = time.ticks_ms()
asyncio.run(test3(d=False))
print('int: ' + str(time.ticks_diff(time.ticks_ms(), t)))
dict(): 427
int: 3556
in unix:
dict(): 4
int: 157
in CPython:
dict(): 4
int: 3
Tested with yesterday's master.
I am a heavy user of asyncio and when I wanted to optimize my code by using simple types rather than creating objects, the result was the opposite. Anyone have any clue?
Thanks.