mcrose has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Coro, AnyEvent and performance
by BrowserUk (Patriarch) on Jul 06, 2011 at 18:35 UTC | |
|
Re: Coro, AnyEvent and performance
by Tanktalus (Canon) on Jul 06, 2011 at 17:03 UTC | |
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 | |
|