-
-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmarking portals vs worker threads #709
Comments
It would be nice to get async support into timeit, but in the mean time a simple timing loop generally works ok: LOOPS = 100000
async def main():
start = time.perf_counter()
for _ in range(LOOPS):
await trio.run_sync_in_worker_thread(lambda: None)
end = time.perf_counter()
print(f"{(end - start)/LOOPS * 10e6:.2f} us/call") Btw, you can also use |
(I made a guess at the |
Oh, I misread what your trick for using timeit was there. Never mind :-). If you're using the ipython magic of course you can't do that from inside a trio worker thread. I don't know why sometimes the portal call takes longer. I'd be curious what the CPU usage is here... Since you have to switch back and forth between threads, it could be something like the os scheduler being lazy about scheduling the other thread or something? And in general it's hard to guess how all of this will generalize to a real program with more stuff going on. |
#677 has some sample code which emulates timeit |
I am trying to determine whether it's better to call worker threads from trio, or to call into trio from worker threads. But I am running into some issues.
First, time needed to enter the trio loop:
This factor of 10 happens every time. Why is p.run_sync() sometimes so slow?
Secondly:
It looks like there is some issue with async functions and timeit... is there another/better way to get the time taken by an async fn?
The text was updated successfully, but these errors were encountered: