/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
1,00012.933.386,104579  95% 96% 98% 96%
4,000211.5252.958,724579  100% 100% 100% 100%
16,0003,308.66828.0041,196579  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 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

 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

Tue, 14 Jan 2014 21:02:06 GMT

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

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play