Given the following code, the runtime and performance depends heavily on where I actually put my poll for new events. If I poll every time through the loop, I get a horrendous performance hit. I can only poll every once in a while by modding against the current iteration, but I'd like to use this in situations where I may not be maintaining an iteration counter or when one doesn't make sense.
Is there a way to simply integrate events into Coro by telling the threading mechanism to poll for new events every n ms or so?
use strict; use warnings; use 5.012; use Coro; use AnyEvent; use Coro::AnyEvent; my $w; $w = AE::timer 0, 1, sub { async { say "timer event" } }; for my $i (1 .. 1000000) { my $computation = $i ** $i; if ($i % 10000 == 0) { say $i; # Coro::AnyEvent::poll; # fast - ~200k iterations/sec } Coro::AnyEvent::poll; # slow - ~25k iterations/sec cede; }
In reply to Coro, AnyEvent and performance by mcrose
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |