Created
June 29, 2009 01:32
-
-
Save tokuhirom/137424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}, | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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