/mobile Handheld Friendly website

 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 x86_64-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_64_BIT_ALL
                        USE_64_BIT_INT 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://benchmarksgame.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

Mon, 04 Feb 2013 05:09:25 GMT

COMMAND LINE:
/usr/local/src/perl-5.16.2/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
4402258 zero
3616129 zero
3981613 zero
 one two zero zero zero zero zero zero

 blue red yellow red yellow blue red yellow red blue
1188415 zero
1222513 zero
1203334 zero
1208234 zero
1215685 zero
1188729 zero
1204677 zero
1198966 zero
1176661 zero
1192786 zero
 one two zero zero zero zero zero zero

Revised BSD license

  Home   Conclusions   License   Play