performance measurements

Each table row shows performance measurements for this Perl program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load

Read the ↓ make, command line, and program output logs to see how this program was run.

Read chameneos-redux benchmark to see what this program should do.

 notes

This is perl 5, version 18, subversion 0 (v5.18.0) built for i686-linux-thread-multi

Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
                        PERL_DONT_CREATE_GVSV
                        PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                        PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                        PERL_PRESERVE_IVUV PERL_SAWAMPERSAND USE_ITHREADS
                        USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE
                        USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO
                        USE_PERL_ATOF USE_REENTRANT_API

 chameneos-redux Perl #3 program source code

# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
# contributed by Jonathan DePeri 2010/5
# based on an earlier version by Jesse Millikan
# uses Perl interpreter threads with pthreads-like cond_wait and cond_signal

use threads;
use threads::shared;

sub complement
{
   my $_ = join('', @_);
   
   s/BB/B/;
   s/BR/Y/;
   s/BY/R/;
   s/RB/Y/;
   s/RR/R/;
   s/RY/B/;
   s/YB/R/;
   s/YR/B/;
   s/YY/Y/;
   
   return $_;
}

sub color_name
{
   my $_ = shift;

   s/B/blue/;
   s/R/red/;
   s/Y/yellow/;

   return $_;
}

sub display_complements
{
   local $\ = "\n";

   print 'blue + blue -> ', color_name(complement('B','B'));
   print 'blue + red -> ', color_name(complement('B','R'));
   print 'blue + yellow -> ', color_name(complement('B','Y'));
   print 'red + blue -> ', color_name(complement('R','B'));
   print 'red + red -> ', color_name(complement('R','R'));
   print 'red + yellow -> ', color_name(complement('R','Y'));
   print 'yellow + blue -> ', color_name(complement('Y','B'));
   print 'yellow + red -> ', color_name(complement('Y','R'));
   print 'yellow + yellow -> ', color_name(complement('Y','Y'));
   print '';
}

sub num2words
{
   my $_ = shift;

   s/0/ zero/g;
   s/1/ one/g;
   s/2/ two/g;
   s/3/ three/g;
   s/4/ four/g;
   s/5/ five/g;
   s/6/ six/g;
   s/7/ seven/g;
   s/8/ eight/g;
   s/9/ nine/g;

   return $_;
}

sub print_color_names
{
   for (@_) { print ' ', color_name($_); }
}


my @colors : shared;
my $meetings : shared;
my $first : shared = undef;
my $second : shared = undef;
my @met : shared;
my @met_self : shared;

sub chameneos
{
   my $id = shift;
   my $other = undef;
   
   while (1) {
      lock $meetings;
      last if ($meetings <= 0);
   
      if (not defined $first) {
         $first = $id;
         cond_wait $meetings;
      } else {
         cond_signal $meetings;
         
         $colors[$first] = $colors[$id] = complement($colors[$first], $colors[$id]);
         $met_self[$first]++ if ($first == $id);      
         $met[$first]++;  $met[$id]++;
         $meetings -= 1;
         
         $first = undef;
      }
   }
}

sub pall_mall
{
   my $N = shift;
   @colors = @_;
   my @threads;
   
   print_color_names(@colors);

   $meetings = $N;
   for (0..@colors-1) {
      $met[$_] = $met_self[$_] = 0;
      $threads[$_] = threads->create(\&chameneos, $_);
   }
   for (@threads) {
     $_->join();
   }
   
   $meetings = 0;
   for (0..@colors-1) {
      print "\n$met[$_]", num2words($met_self[$_]);
      $meetings += $met[$_];
     }
   print "\n", num2words($meetings), "\n\n";
}


display_complements();
pall_mall($ARGV[0], qw(B R Y));
pall_mall($ARGV[0], qw(B R Y R Y B R Y R B));

 make, command-line, and program output logs

Sun, 15 May 2011 23:01:21 GMT

COMMAND LINE:
/usr/local/src/perl-5.14.0/bin/perl chameneosredux.perl-3.perl 6000000

PROGRAM OUTPUT:
blue + blue -> blue
blue + red -> yellow
blue + yellow -> red
red + blue -> yellow
red + red -> red
red + yellow -> blue
yellow + blue -> red
yellow + red -> blue
yellow + yellow -> yellow

 blue red yellow
3983741 zero
4083939 zero
3932320 zero
 one two zero zero zero zero zero zero

 blue red yellow red yellow blue red yellow red blue
1167716 zero
1192802 zero
1194183 zero
1209375 zero
1223748 zero
1188365 zero
1222432 zero
1174883 zero
1236465 zero
1190031 zero
 one two zero zero zero zero zero zero

Revised BSD license

  Home   Conclusions   License   Play