x64 ArchLinux : AMD® Ryzen 7 4700U®

Each chart bar shows *how many times slower*, one ↓ **fannkuch-redux** program was, compared to the fastest program.

These are not the only programs that could be written. These are not the only compilers and interpreters. These are not the only programming languages.

Column × shows *how many times more* each program used compared to the benchmark program that used least.

sort | sort | sort | ||||

× | Program Source Code | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
---|---|---|---|---|---|---|

1.0 | Pyston #4 |
3.22 | 0.45 | 95,304 | 1069 | 91% 98% 91% 91% 85% 91% 91% 93% |

1.0 | Pyston #3 |
3.19 | 0.46 | 96,672 | 894 | 78% 92% 87% 89% 85% 89% 87% 91% |

1.3 | Python development version #3 |
4.09 | 0.57 | 97,032 | 894 | 93% 84% 91% 92% 96% 91% 91% 91% |

1.3 | PyPy 2 |
1.68 | 0.58 | 322,008 | 1009 | 41% 19% 66% 16% 43% 68% 66% 32% |

1.3 | Python development version #4 |
4.36 | 0.60 | 97,116 | 1069 | 92% 92% 90% 92% 97% 95% 92% 86% |

1.4 | Nuitka #3 |
4.48 | 0.62 | 102,152 | 894 | 92% 90% 98% 89% 92% 84% 92% 90% |

1.5 | Python 3 #3 |
4.72 | 0.65 | 99,300 | 894 | 91% 97% 91% 91% 85% 92% 91% 93% |

1.5 | PyPy 3 #2 |
1.72 | 0.67 | 80,080 | 1008 | 14% 15% 55% 53% 47% 40% 46% 1% |

1.5 | PyPy 3 #3 |
2.78 | 0.68 | 80,052 | 894 | 49% 93% 52% 52% 48% 52% 53% 46% |

1.5 | PyPy 3 |
1.79 | 0.69 | 80,296 | 1271 | 16% 23% 56% 53% 93% 35% 3% 1% |

1.6 | PyPy 3 #4 |
3.11 | 0.73 | 80,028 | 1069 | 54% 54% 56% 49% 93% 58% 53% 55% |

1.7 | PyPy 3 #6 |
0.74 | 0.75 | 69,036 | 552 | 3% 3% 1% 3% 100% 0% 0% 0% |

1.7 | Python 3 #4 |
5.70 | 0.78 | 100,164 | 1069 | 94% 91% 97% 94% 92% 87% 94% 92% |

1.9 | Pyston #2 |
3.24 | 0.85 | 52,900 | 1008 | 96% 89% 19% 5% 2% 6% 91% 95% |

2.3 | Nuitka #4 |
7.68 | 1.04 | 102,820 | 1069 | 86% 94% 95% 92% 96% 91% 93% 95% |

2.7 | Python development version #2 |
4.60 | 1.20 | 55,692 | 1008 | 97% 95% 6% 3% 2% 92% 97% 1% |

2.8 | Nuitka #2 |
4.74 | 1.24 | 60,544 | 1008 | 93% 95% 12% 2% 94% 96% 6% 2% |

3.0 | Python development version |
5.21 | 1.35 | 56,412 | 1271 | 13% 1% 96% 92% 90% 99% 1% 1% |

3.1 | Python 3 #2 |
5.36 | 1.40 | 55,064 | 1008 | 14% 97% 1% 95% 92% 1% 96% 1% |

3.5 | Python 3 |
6.02 | 1.56 | 55,964 | 1271 | 94% 97% 5% 3% 1% 6% 93% 97% |

4.7 | Nuitka |
8.08 | 2.08 | 60,196 | 1271 | 94% 4% 5% 98% 2% 95% 97% 1% |

5.2 | Pyston #6 |
2.32 | 2.32 | 7,860 | 552 | 1% 1% 2% 1% 0% 100% 0% 0% |

6.4 | Python 2 |
11.02 | 2.85 | 11,460 | 1009 | 6% 4% 97% 95% 94% 0% 1% 96% |

7.0 | Nuitka #6 |
3.11 | 3.11 | 11,008 | 552 | 2% 0% 100% 1% 0% 0% 2% 1% |

7.2 | Python development version #6 |
3.23 | 3.23 | 8,564 | 552 | 5% 100% 0% 2% 0% 0% 0% 0% |

7.8 | Python 3 #6 |
3.46 | 3.47 | 10,192 | 552 | 1% 0% 1% 0% 100% 0% 0% 1% |

7.8 | Graal #6 |
3.86 | 3.47 | 735,676 | 552 | 93% 75% 86% 90% 76% 86% 98% 70% |

16 | MicroPython #6 |
7.01 | 7.01 | 4,180 | 552 | 2% 1% 2% 2% 1% 0% 100% 1% |

127 | RustPython #6 |
56.75 | 56.77 | 15,068 | 552 | 2% 1% 1% 1% 1% 100% 1% 1% |

missing benchmark programs | ||||||

Jython |
No program | |||||

IronPython |
No program | |||||

Cython |
No program | |||||

Shedskin |
No program | |||||

Numba |
No program | |||||

Grumpy |
No program |

**diff** program output N = 7 with this output file to check your program is correct before contributing.

We are trying to show the performance of various programming language implementations - so we ask that contributed programs not only give the correct result, but also **use the same algorithm** to calculate that result.

For N = 7 programs should generate these permutations (40KB) - which, incidentally, seem to be in the same order as permutations generated by the Tompkins-Paige algorithm, see pages 150-151 Permutation Generation Methods Robert Sedgewick.

The fannkuch benchmark is defined by programs in Performing Lisp Analysis of the FANNKUCH Benchmark, Kenneth R. Anderson and Duane Rettig.

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.

The conjecture is that this maximum count is approximated by n*log(n) when n goes to infinity.

*FANNKUCH* is an abbreviation for the German word *Pfannkuchen*, or pancakes, in analogy to flipping pancakes.

Thanks to Oleg Mazurov for insisting on a checksum and providing this helpful description of the approach he took -

- A common idea for parallel implementation is to divide all work (n! permutations) into chunks small enough to avoid load imbalance but large enough to keep overhead low. I set the number of chunks as a parameter (NCHUNKS = 150) from which I derive the size of a chunk (CHUNKSZ) and the actual number of chunks/tasks to be processed (NTASKS), which may be different from NCHUNKS because of rounding.
- Task scheduling is trivial: threads will atomically get and increment the taskId variable to derive a range of permutation indices to work on:
task = taskId.getAndIncrement(); idxMin = task * CHUNKSZ; idxMax = min( idxMin + CHUNKSZ, n! );

- Maximum flip counts and partial checksums can be computed for chunks in arbitrary order and recombined to generate the required result at the final step (CHUNKSZ must be even for adding partial checksums to be associative - I didn't enforce it in my submission).
- Now I need to go from a permutation index to the permutation itself.
- The predefined order in which all permutations are to be generated can be described as follows: to generate n! permutations of n arbitrary numbers, rotate the numbers left (from higher position to lower) n times, so that each number appears in the n-th position, and for each rotation recursively generate (n-1)! permutations of the first n-1 numbers whatever they are.
- To optimize the process I use an intermediate data structure, count[], which keeps count of how many rotations have been done at every level. Apparently, count[0] is always 0, as there is only one element at that level, which can't be rotated; count[1] = 0..1 for two elements, count[2] = 0..2 for three elements, etc.
- To generate next permutation I swap the first two elements and increase count[1]. If count[1] becomes greater than 1, I'm done with rotations at level 1 and need to "return" (as it would have been in the recursive implementation) to level 2. Now, I rotate 3 elements and increment count[2]. If it becomes greater than 2, I'm done with level 2 and need to go to level 3, etc.
- It should be clear now how to generate a permutation and corresponding count[] array from an arbitrary index. Basically, count[k] = ( index % (k+1)! ) / k! is the number of rotations we need to perform on elements 0..k. Doing it in the descending order from n-1 to 1 gives us both the count[] array and the permutation.