$ diff hobo_test.pl threads_test.pl
5,6c5,6
< use MCE::Hobo;
< use Foo::Inbox2;
---
> use threads;
> use Foo::Inbox4;
11c11
< my $inbox = Foo::Inbox2->new( @names );
---
> my $inbox = Foo::Inbox4->new( @names );
38,39c38,39
< MCE::Hobo->create(\&foo, $_) for @names;
< MCE::Hobo->waitall;
---
> threads->create(\&foo, $_) for @names;
> $_->join() for threads->list();
####
use strict;
use warnings;
use MCE::Hobo;
use Foo::Inbox2;
use List::Util qw( shuffle );
use Time::HiRes qw( time );
my @names = shuffle qw/ Barny Betty Fred Wilma /;
my $inbox = Foo::Inbox2->new( @names );
my $start = time;
$| = 1;
sub foo {
my $name = shift;
my $count = 0;
# remove my name from the list
@names = grep { $_ ne $name } shuffle @names;
# send greeting
$inbox->send($name, \@names, 'Hello');
while ( my ($from, $data) = $inbox->recv($name) ) {
# display the message received
printf "%-5s received %s from %s\n", $name, $data->[0], $from;
# send greeting again
$inbox->send($name, \@names, 'Hello') if $count < 4167;
# eventually stop benchmarking
last if ++$count == 12500;
}
}
MCE::Hobo->create(\&foo, $_) for @names;
MCE::Hobo->waitall;
printf {*STDERR} "duration: %0.03f seconds\n", time - $start;
##
##
use strict;
use warnings;
use threads;
use Foo::Inbox4;
use List::Util qw( shuffle );
use Time::HiRes qw( time );
my @names = shuffle qw/ Barny Betty Fred Wilma /;
my $inbox = Foo::Inbox4->new( @names );
my $start = time;
$| = 1;
sub foo {
my $name = shift;
my $count = 0;
# remove my name from the list
@names = grep { $_ ne $name } shuffle @names;
# send greeting
$inbox->send($name, \@names, 'Hello');
while ( my ($from, $data) = $inbox->recv($name) ) {
# display the message received
printf "%-5s received %s from %s\n", $name, $data->[0], $from;
# send greeting again
$inbox->send($name, \@names, 'Hello') if $count < 4167;
# eventually stop benchmarking
last if ++$count == 12500;
}
}
threads->create(\&foo, $_) for @names;
$_->join() for threads->list();
printf {*STDERR} "duration: %0.03f seconds\n", time - $start;
##
##
# Mac OS X ( Perl v5.18.2 )
$ perl foo1.pl | wc -l # Foo::Inbox
duration: 0.690 seconds
50000
$ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability
duration: 0.721 seconds
50000
$ perl foo2.pl | wc -l # MCE::Shared->queue
duration: 0.789 seconds
50000
$ perl foo4.pl | wc -l # Thread::Queue
duration: 5.735 seconds
50000
# CentOS 7 VM ( Perl v5.16.3 )
$ perl foo1.pl | wc -l # Foo::Inbox
duration: 0.834 seconds
50000
$ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability
duration: 0.726 seconds
50000
$ perl foo2.pl | wc -l # MCE::Shared->queue
duration: 0.945 seconds
50000
$ perl foo4.pl | wc -l # Thread::Queue
duration: 3.020 seconds
50000
##
##
# Windows ( Cygwin Perl v5.22.3 )
$ perl foo1.pl | wc -l # Foo::Inbox
duration: 1.825 seconds
50000
$ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability
duration: 2.059 seconds
50000
$ perl foo2.pl | wc -l # MCE::Shared->queue
duration: 2.387 seconds
50000
$ perl foo4.pl | wc -l # Thread::Queue
duration: 24.086 seconds
50000
# Windows ( Strawberry Perl v5.22.2.1 )
$ perl foo1.pl > nul # Foo::Inbox
duration: 1.570 seconds
$ perl inbox.pl > nul # MCE::Inbox w/ blocking capability
duration: 1.664 seconds
$ perl foo2.pl > nul # MCE::Shared->queue
duration: 2.120 seconds
$ perl foo4.pl > nul # Thread::Queue
duration: 2.886 seconds
##
##
# TrueOS 10.0 ( FreeBSD, Perl 5.16.3 )
$ perl foo1.pl | wc -l # Foo::Inbox
duration: 0.910 seconds
50000
$ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability
duration: 0.875 seconds
50000
$ perl foo2.pl | wc -l # MCE::Shared->queue
duration: 1.107 seconds
50000
$ perl foo4.pl | wc -l # Thread::Queue
duration: 0.797 seconds
50000
# Solaris 11.2 ( Perl 5.22.2 )
$ perl foo1.pl | wc -l # Foo::Inbox
duration: 1.319 seconds
50000
$ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability
duration: 1.344 seconds
50000
$ perl foo2.pl | wc -l # MCE::Shared->queue
duration: 1.525 seconds
50000
$ perl foo4.pl | wc -l # Thread::Queue
duration: 1.822 seconds
50000