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
10Failed  565   

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 18, subversion 0 (v5.18.0) built for i686-linux

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

 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

Tue, 07 Jan 2014 03:03:12 GMT

COMMAND LINE:
/usr/local/src/perl-5.18.0_no_ithreads_no_multi/bin/perl fannkuchredux.perl-2.perl 10

PROGRAM FAILED 


PROGRAM OUTPUT:

This Perl not built to support threads
Compilation failed in require at fannkuchredux.perl-2.perl line 7.
BEGIN failed--compilation aborted at fannkuchredux.perl-2.perl line 7.

Revised BSD license

  Home   Conclusions   License   Play