shazamio / ShazamIO

🎵 Is a free asynchronous library from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp.
MIT License
519 stars 75 forks source link

[Feature] Recognize to Rust Language #78

Closed dotX12 closed 9 months ago

dotX12 commented 11 months ago

Recognize from Python to Rust

Currently, active work is underway to unload the processor; searching for a signature is a complex operation for the CPU, especially for a language where there is an asynchronous approach, because of this, asynchrony for the recoginze method disappears. What has already been done: The search for song signatures from Python to Rust has been rewritten. integration of this module through pyo3, as is done with pydantic.

There is very little left, but now you can see the preliminary results.

Before

Test for 20 iterations.

async def main():
    shazam = Shazam()
    t = time.perf_counter()
    a = await asyncio.gather(*[shazam.recognize_song("data/dora.ogg") for _ in range(20)])  # blocking code
    t2 = time.perf_counter()
    print(t2-t)

loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
>>> 23.145966300013242

After:

Test for 50 iterations.

async def main():
    sender = rust.Recognizer()
    t = time.perf_counter()
    a = await asyncio.gather(*[sender.recognize_path("data/dora.ogg") for _ in range(50)])
    t2 = time.perf_counter()
    print(t2 - t)
>>> 2.246784299990395
dotX12 commented 9 months ago

https://github.com/shazamio/ShazamIO/issues/76#issuecomment-1961610344