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
1015.133.865,688565  98% 99% 98% 98%
11182.1545.836,116565  100% 100% 99% 99%
122,380.95598.6212,380565  100% 100% 99% 99%

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

Read fannkuch-redux 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

 fannkuch-redux Perl #2 program source code

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

use strict;
use threads;
use integer;

my($max_flips, $chksum, $sign, $n, $p, $count, @threads, $thr, $t_chksum, $t_max_flips);

sub count_flips($) {
    my $p = shift;
    my $flips = 0;
    my($first);

# debug permutation order:
#print unpack('c*', $p), "\n";
    while($first = vec($p, 0, 8)) {
        $first ++;
        $flips ++;
        substr($p, 0, $first, reverse(substr($p, 0, $first)));
    }
    $max_flips = $flips if $flips > $max_flips;
    $chksum += $sign * $flips;
    $sign = -$sign;
}

sub fannkuchredux($$) {
    my $p = shift;
    my $rotate_len = shift;

# optimize case when rotation is equivalent to byte-swapping
    if($rotate_len == 3) {
        count_flips($p);
        substr($p, 0, 2, reverse(substr($p, 0, 2)));
        count_flips($p);
        substr($p, 1, 2, reverse(substr($p, 1, 2)));
        count_flips($p);
        substr($p, 0, 2, reverse(substr($p, 0, 2)));
        count_flips($p);
        substr($p, 1, 2, reverse(substr($p, 1, 2)));
        count_flips($p);
        substr($p, 0, 2, reverse(substr($p, 0, 2)));
        count_flips($p);
        return($chksum, $max_flips);
    } elsif($rotate_len == 2) {
        count_flips($p);
        substr($p, 0, 2, reverse(substr($p, 0, 2)));
        count_flips($p);
        return($chksum, $max_flips);
    } elsif($rotate_len == 1) {
        count_flips($p);
        return($chksum, $max_flips);
    }

    $rotate_len --;
    my $count = $rotate_len;
    for(;;) {
        fannkuchredux($p, $rotate_len);
        $count --;
        last if $count < 0;	# skip unneccessary rotation
        substr($p, 0, $rotate_len + 1) = substr($p, 1, $rotate_len) . substr($p, 0, 1);
    }
    return($chksum, $max_flips);
}

## MAIN()

$n = shift;
$p = pack('c*', (0 .. $n - 1));
$sign = 1;

$count = $n;
while($count > 0) {
    push @threads, threads->create(\&fannkuchredux, $p, $n-1);
    $p = substr($p, 1, $n-1) . substr($p, 0, 1);
    $count --;
}

foreach $thr (@threads) {
    ($t_chksum, $t_max_flips) = $thr->join();
    $chksum += $t_chksum;
    $max_flips = $t_max_flips if $max_flips < $t_max_flips;
}

print "$chksum\n";
print "Pfannkuchen($n) = $max_flips\n";

 make, command-line, and program output logs

Sun, 15 Mar 2015 07:48:01 GMT

COMMAND LINE:
/usr/local/src/perl-5.20.2/bin/perl fannkuchredux.perl-2.perl 12

PROGRAM OUTPUT:
3968050
Pfannkuchen(12) = 65

Revised BSD license

  Home   Conclusions   License   Play