package Benchmark::Forking; use strict; use Benchmark; use vars qw( $VERSION $Enabled $RunLoop ); BEGIN { $VERSION = 0.9; $Enabled = 1; $RunLoop = \&Benchmark::runloop; } sub enable { $Enabled = 1 } sub disable { $Enabled = 0 } sub enabled { $#_ ? $Enabled = $_[1] : $Enabled } sub import { enable(); goto &Benchmark::import } sub unimport { disable() } sub Benchmark::runloop { $Enabled or return &$RunLoop; open( FORK, '-|') or print join "\n", @{ &$RunLoop } and exit; my @td = ; close( FORK ) or die $!; bless \@td, 'Benchmark'; }; 1;