Hypersonic
view release on metacpan or search on metacpan
bench/future-benchmark.pl view on Meta::CPAN
}, 'Hypersonic::Future');
}
print "\n";
# ============================================================================
# Hypersonic-only tests (callback-based operations)
# ============================================================================
print "=" x 70, "\n";
print "Hypersonic::Future Only Tests (callback operations)\n";
print "=" x 70, "\n";
print "(Future::XS 0.15 has wrap_cb issues with callbacks)\n\n";
# ============================================================================
# Test 9: then() chaining (Hypersonic only)
# ============================================================================
print "-" x 70, "\n";
print "Test 9: then() - Chain transformation [Hypersonic only]\n";
print "-" x 70, "\n";
timethis(-$bench_time, sub {
my $f = Hypersonic::Future->new;
my $f2 = $f->then(sub { return $_[0] * 2 });
$f->done(21);
}, 'Hypersonic::Future');
print "\n";
# ============================================================================
# Test 10: on_done callback (Hypersonic only)
# ============================================================================
print "-" x 70, "\n";
print "Test 10: on_done() + done() - Callback [Hypersonic only]\n";
print "-" x 70, "\n";
my $counter = 0;
timethis(-$bench_time, sub {
my $f = Hypersonic::Future->new;
$f->on_done(sub { $counter++ });
$f->done('value');
}, 'Hypersonic::Future');
print "\n";
# ============================================================================
# Test 11: Full chain (Hypersonic only) - uses fixed iteration count
# ============================================================================
print "-" x 70, "\n";
print "Test 11: then()->catch()->finally() [Hypersonic only]\n";
print "-" x 70, "\n";
# Chained futures use ~4 registry slots per iteration, so limit to 10000
my $chain_iter = 10000;
my $start = time();
for (1..$chain_iter) {
my $f = Hypersonic::Future->new;
my $chain = $f->then(sub { $_[0] * 2 })
->catch(sub { 0 })
->finally(sub { });
$f->done(21);
}
my $elapsed = time() - $start;
my $rate = $chain_iter / $elapsed;
printf "Hypersonic::Future: %.0f/s (%d iterations in %.2f seconds)\n", $rate, $chain_iter, $elapsed;
print "\n";
# ============================================================================
# Summary
# ============================================================================
print "=" x 70, "\n";
print "Benchmark complete!\n";
print "=" x 70, "\n";
if ($has_future_xs) {
print "\nResults interpretation:\n";
print " - Higher Rate = faster (more operations per second)\n";
print " - Positive % = that implementation is faster by that percentage\n";
}
print "\nHypersonic::Future advantages:\n";
print " - Blessed scalar objects (minimal allocation overhead)\n";
print " - JIT-compiled XS code (optimized for specific operations)\n";
print " - Pre-allocated registry (O(1) slot allocation)\n";
print " - Custom ops for zero-overhead state checks\n";
print " - Direct C-level callback invocation\n";
( run in 0.598 second using v1.01-cache-2.11-cpan-5511b514fd6 )