Skip to content

Language Shootout

A user-supported site Fastest, Shortest, Simplest

Benchmarks

Fannkuch-Redux

Background

The fannkuch benchmark is defined by programs in "Performing Lisp Analysis of the FANNKUCH Benchmark", Kenneth R. Anderson and Duane Rettig. FANNKUCH is an abbreviation for the German word Pfannkuchen, or pancakes, in analogy to flipping pancakes. The conjecture is that the maximum count is approximated by n*log(n) when n goes to infinity.

How to implement

We ask that contributed programs not only give the correct result, but also use the same algorithm to calculate that result.

Each program should:

  • Take a permutation of {1,...,n}, for example: {4,2,1,5,3}.
  • Take the first element, here 4, and reverse the order of the first 4 elements: {5,1,2,4,3}.
  • Repeat this until the first element is a 1, so flipping won't change anything more: {3,4,2,1,5}, {2,4,3,1,5}, {4,2,3,1,5}, {1,3,2,4,5}.
  • Count the number of flips, here 5.
  • Keep a checksum:
    • checksum = checksum + (if permutation_index is even then flips_count else -flips_count)
    • checksum = checksum + (toggle_sign_-1_1 * flips_count)
  • Do this for all n! permutations, and record the maximum number of flips needed for any permutation.

Verification: Use diff to compare program output N=7 with the reference output.

Use a larger command line argument (12) to check program performance.

Times are wall-clock milliseconds, with this implementation’s hello-world startup time subtracted. gz is the source in bytes with comments removed and gzipped. style is the idiomatic-code score. Click a heading to sort.

# source ms cpu ms mem KB gz style by
1 Fortran gfortran #1 27,424.7 27,414.9 7,304 612 ★★★☆☆ sysop-
2 PHP #1 252,018.6 250,923.6 22,140 542 ★★★☆☆ sysop-