Closed indiqn closed 7 months ago
@indiqn, hello! https://github.com/dotX12/ShazamIO/issues/12
0.5.0 Release (https://github.com/shazamio/ShazamIO/releases/tag/0.5.0) ! Enormous acceleration and no blocking, real async!
Test 1.
async def main():
t1 = time.time()
for i in range(10):
new_version_path = await shazam.recognize("data/dora.ogg")
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)
t2 = time.time()
print(t2 - t1)
# 7.2795631885528564 - recognize_song (OLD VERSION)
# 3.6113240718841553 - recognize (NEW VERSION)
Test 2.
async def test_old(shazam):
new_version_path = await shazam.recognize_song("data/dora.ogg")
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)
async def test_new(shazam):
new_version_path = await shazam.recognize("data/dora.ogg")
serialized_new_path = Serialize.full_track(new_version_path)
print(serialized_new_path)
async def main():
shazam = Shazam()
t1 = time.time()
a = asyncio.gather(*[test_old(shazam) for _ in range(10)])
a = asyncio.gather(*[test_new(shazam) for _ in range(20)])
await a
t2 = time.time()
print(t2-t1)
# recognize_song - 5.2275474071502686
# recognize - 0.5232067108154297
I made a small experiment to understand the benefit of using asyncio but so far I found that there's no improvement over making synchronous requests to the API. It takes around 4 seconds for one request and the total time for the program scales with the number of calls. I've even made each request run in its own thread but the result was still the same. I am quite confused by this behaviour.
Does anyone have insights into this ?