EV-Future
view release on metacpan or search on metacpan
## Install
```bash
perl Makefile.PL && make && make test
```
Requires Perl 5.10+, EV 4.37+, and a C compiler.
## Benchmarks
1000 sync tasks x 5000 iterations:
| | parallel | parallel_limit(10) | series |
|---|---:|---:|---:|
| EV::Future (unsafe) | 4,386 | 4,673 | 5,000 |
| EV::Future (safe) | 2,262 | 2,688 | 2,591 |
| AnyEvent cv | 1,027 | - | 3,185 |
| Future::XS | 982 | 431 | 893 |
| Promise::XS | 32 | - | 809 |
Safe mode adds per-task double-call protection and `G_EVAL`. Unsafe mode skips both, roughly doubling throughput.
bench/benchmark.pl view on Meta::CPAN
print "Running $name...\n";
my $start = time;
for (1..$ITERATIONS) {
$code->();
}
my $end = time;
my $elapsed = $end - $start;
printf "%-30s: %8.4fs (%10.2f/s)\n", $name, $elapsed, $ITERATIONS / $elapsed;
}
print "Benchmarking $COUNT synchronous tasks over $ITERATIONS iterations:\n";
run_bench('EV::Future::parallel', sub {
EV::Future::parallel(\@tasks, sub { });
});
run_bench('EV::Future::parallel (unsafe)', sub {
EV::Future::parallel(\@tasks, sub { }, 1);
});
run_bench('EV::Future::parallel_limit(10)', sub {
bench/comparison.pl view on Meta::CPAN
}
sub bench_future_fmap_void {
my @items = 1..$COUNT;
my $f = fmap_void {
return Future->done;
} foreach => \@items, concurrent => 10;
$f->get;
}
print "Benchmarking $COUNT tasks ($ITERATIONS iterations):\n";
print "\n--- PARALLEL ---\n";
timethese($ITERATIONS, {
'EV::Future::parallel' => \&bench_ev_future_parallel,
'EV::Future::parallel (unsafe)' => \&bench_ev_future_parallel_unsafe,
'Promise::XS::all' => \&bench_promise_xs_parallel,
'Future::XS::wait_all' => \&bench_future_xs_parallel,
'AnyEvent::cv (begin/end)' => \&bench_anyevent_parallel,
});
lib/EV/Future.pm view on Meta::CPAN
race([
sub { my $d = shift; push @w, EV::timer 0.1, 0, sub { $d->("a") } },
sub { my $d = shift; push @w, EV::timer 0.2, 0, sub { $d->("b") } },
], sub { my $winner = shift; @w = () });
Non-coderef elements in C<\@tasks> count as instantly-completed winners
(with no arguments) and short-circuit dispatch.
=head1 BENCHMARKS
1000 synchronous tasks, 5000 iterations (C<bench/comparison.pl>):
--- PARALLEL (iterations/sec) ---
EV::Future (unsafe) 4,386
EV::Future (safe) 2,262
AnyEvent::cv (begin/end) 1,027
Future::XS::wait_all 982
Promise::XS::all 32
--- PARALLEL LIMIT 10 (iterations/sec) ---
EV::Future (unsafe) 4,673
EV::Future (safe) 2,688
Future::Utils::fmap_void 431
--- SERIES (iterations/sec) ---
EV::Future (unsafe) 5,000
AnyEvent::cv (stack-safe) 3,185
EV::Future (safe) 2,591
Future::XS (chain) 893
Promise::XS (chain) 809
=head1 SEE ALSO
L<EV>, L<Future::XS>, L<Promise::XS>
( run in 0.904 second using v1.01-cache-2.11-cpan-71847e10f99 )