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
1,00013.973.5410,952579  99% 99% 99% 99%
4,000228.4457.227,164579  100% 100% 100% 100%
16,0003,720.50931.4844,184579  100% 100% 100% 100%

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

Read mandelbrot benchmark to see what this program should do.

 notes

This is perl 5, version 20, subversion 2 (v5.20.2) 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_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
                        USE_ITHREADS USE_LARGE_FILES USE_LOCALE
                        USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
                        USE_REENTRANT_API

 mandelbrot Perl program source code

# The Computer Language Benchmarks Game
#  http://benchmarksgame.alioth.debian.org/
#
#  contributed by Mykola Zubach

use strict;
use threads;
use threads::shared;

use constant MAXITER => 50;
use constant LIMIT => 4.0;
use constant XMIN => -1.5;
use constant YMIN => -1;
use constant WHITE => "\0";
use constant BLACK => "\001";

my ($w, $h, @threads, $invN);
my @jobs :shared;
my @picture :shared;

sub draw_line($) {
   my $y = shift;
   my $line;
   my $Ci = $y * $invN + YMIN;
X:
   for my $x (0 .. $w - 1) {
      my ($Zr, $Zi, $Tr, $Ti);
      my $Cr = $x * $invN + XMIN;

      for (1 .. MAXITER) {
         $Zi = $Zi * 2 * $Zr + $Ci;
         $Zr = $Tr - $Ti + $Cr;
         $Ti = $Zi * $Zi;
         $Tr = $Zr * $Zr;
         if ($Tr + $Ti > LIMIT) {
            $line .= WHITE;
            next X;
         }
      }
      $line .= BLACK;
   }
   $picture[$y] = pack 'B*', $line;
}

sub process_queue() {
   while(defined(my $y = pop @jobs)) {
      draw_line($y);
   }
}

sub num_cpus() {
   open my $fh, '</proc/cpuinfo' or return 4;
   my $cpus;
   while(<$fh>) {
      $cpus ++ if /^processor\s+:/;
   }
   return $cpus;
}

## MAIN()

$w = $h = shift || 200;
$invN = 2 / $w;
@jobs = (0 .. $h - 1);

for (1 .. num_cpus()) {
   push @threads, threads->create(\&process_queue);
}

for (@threads) {
   $_->join;
}

print "P4\n$w $h\n"; # PBM image header
print @picture;

 make, command-line, and program output logs

Sun, 15 Mar 2015 09:36:36 GMT

COMMAND LINE:
/usr/local/src/perl-5.20.2/bin/perl mandelbrot.perl 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play