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.3015.321,468457  1% 2% 1% 100%
11183.89184.011,468457  0% 0% 0% 100%
122,428.622,429.611,464457  0% 0% 0% 100%

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 program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
# initial fannkuch port from C by Steve Clark
#   rewrite by Kalev Soikonen
#   modified by Kuang-che Wu
#   modified by David Golden
# updated for fannkuch-redux by Jonathan DePeri
#   permutations generated using Mike Pall's approach

use integer;

sub fannkuchredux {
    my ($n) = shift;
    my ($m, $checksum, $maxflips, $flips, $sign) = ($n-1, 0, 0, 0, 1);
    my ($p, $q, $f, $i, @count);
    
    @count = (0..$m); 
    $p = pack "c*", @count;

    do {
        if (ord(substr($p,0))) {
            $q = $p;
            $flips = 0;
            while ($f = ord(substr($q,0))) {
                $flips++;
                substr($q, 0, $f+1, reverse(substr($q,0,$f+1)));
            }
            $maxflips = $flips if ($flips > $maxflips);
            $checksum += ($sign * $flips);
        }
        
        return if ($n <= 1);
        if ($sign == 1) {
            $sign = -1;
            substr $p, 1, 0, (substr($p,0,1,""));
        } else {
            return if ($n <= 2);
            $sign = 1;
            substr $p, 1, 0, (substr($p,2,1,""));
            for $i (2..$m) {
	            if ($count[$i]) { $count[$i]--; last; }
	            return ($checksum, $maxflips) if ($i == $m);
	            $count[$i] = $i;
	            substr $p, $i+1, 0, (substr($p,0,1,""));
            }
        }
    } while (1);
}

for (shift) {
    exit -1 if ((not defined $_) || $_ < 1);
    my ($checksum, $maxflips) = fannkuchredux($_);
    print "$checksum\n";
    print "Pfannkuchen($_) = $maxflips\n";
}

 make, command-line, and program output logs

Tue, 21 May 2013 17:57:29 GMT

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

PROGRAM OUTPUT:
3968050
Pfannkuchen(12) = 65

Revised BSD license

  Home   Conclusions   License   Play