Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created June 29, 2009 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokuhirom/137424 to your computer and use it in GitHub Desktop.
Save tokuhirom/137424 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Coro ();
use Benchmark ':all';
use DateTime;
cmpthese(
10000 => {
'fork' => sub {
my $pid = fork();
if ($pid == 0) { # child
exit;
} elsif ($pid) { # parent
waitpid($pid, 0);
} else {
die $!;
}
},
coro => sub {
my $coro = Coro::async(sub { });
$coro->join;
},
},
);
use strict;
use warnings;
use threads;
use Benchmark ':all';
use DateTime;
cmpthese(
1000 => {
threads => sub {
threads->create(sub { })->join;
},
'fork' => sub {
my $pid = fork();
if ($pid == 0) { # child
exit;
} elsif ($pid) { # parent
waitpid($pid, 0);
} else {
die $!;
}
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment