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 | PyPy 3 #6 |
0.74 | 0.75 | 69,036 | 552 | 3% 3% 1% 3% 100% 0% 0% 0% |

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

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

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

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

3.6 | Nuitka #6 |
2.70 | 2.70 | 10,508 | 552 | 1% 1% 1% 0% 0% 100% 1% 1% |

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

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

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

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

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

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

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

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

5.6 | Nuitka #3 |
4.17 | 0.59 | 96,868 | 894 | 87% 90% 90% 86% 88% 97% 92% 90% |

5.7 | Nuitka #4 |
4.26 | 0.60 | 95,680 | 1069 | 89% 83% 89% 92% 88% 90% 87% 92% |

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

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

6.3 | Nuitka #2 |
4.69 | 1.23 | 60,428 | 1008 | 93% 96% 15% 2% 95% 94% 3% 0% |

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

7.4 | Nuitka |
5.47 | 1.42 | 58,784 | 1271 | 100% 5% 95% 1% 1% 93% 96% 2% |

7.6 | Python 3 #6 |
5.63 | 5.64 | 8,096 | 552 | 49% 21% 20% 16% 69% 19% 12% 13% |

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

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

16 | Python 3 #2 |
11.97 | 3.07 | 12,672 | 1008 | 97% 26% 98% 14% 8% 96% 98% 6% |

18 | Python 3 #3 |
13.67 | 2.31 | 12,852 | 894 | 87% 84% 97% 85% 90% 94% 89% 87% |

20 | Python 3 #4 |
14.55 | 2.20 | 12,812 | 1069 | 94% 95% 94% 90% 98% 90% 93% 90% |

22 | Python 3 |
16.04 | 4.12 | 12,888 | 1271 | 98% 94% 29% 28% 30% 98% 99% 21% |

76 | 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.