in reply to Coro, AnyEvent and performance
What you want is for a kernel running outside of your application to forcefully take the CPU from you whenever it feels it necessary to do so. That is True Threading, which Coro is decidedly not.
Your problem in your example code is that your loop is very, very short. You're computing a simple exponential (ok, near the end it's not so simple). The time for Coro/AnyEvent to figure out if there are any other events to process, process them, and come back to you, quite simply overwhelms your loop.
If your loop was doing "real work" in the middle, you might find the overhead of poll/cede to be far less significant.
For example, if your loop was using, say, AnyEvent::HTTP to query a web site, you wouldn't even need to poll/cede. Or if your loop was rendering some Template Toolkit output, that may be heavy enough that ceding each time through the loop may be minor.
The reality is, these things have overhead that they need to go check everything before coming back to where you are. As long as you can push your hard work off into asynchronous pieces of work that need to wait for things (such as sockets, e.g., TCP/IP requests, or user events), Coro will net you a speed up. But if you're doing something computationally trivial between cede's, that's not going to seem like a benefit :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Coro, AnyEvent and performance
by mcrose (Beadle) on Jul 06, 2011 at 17:38 UTC | |
by Tanktalus (Canon) on Jul 06, 2011 at 19:11 UTC | |
by BrowserUk (Patriarch) on Jul 06, 2011 at 19:19 UTC | |
by Tanktalus (Canon) on Jul 06, 2011 at 19:52 UTC | |
|