performance measurements

Each table row shows performance measurements for this Cython program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1010.152.8653,2721027  97% 98% 94% 98%
1010.142.9852,3321027  96% 94% 94% 88%
1010.102.9252,9441027  92% 92% 86% 94%

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

 fannkuch-redux Cython program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
#
# contributed by Jacek Pliszka
# algorithm is based on Java 6 source code by Oleg Mazurov
# source is based on Miroslav Rubanets' C++ submission.
# converted to python by Ian P. Cooke
# converted to generators by Jacek Pliszka

import sys
import math
from multiprocessing import cpu_count, Pool

cdef int MAX_PROBLEM_SIZE, MAX_CPU_LIMIT

MAX_PROBLEM_SIZE = 12
MAX_CPU_LIMIT = 4


def PermutationGenerator(int length, int idx):
    cdef int i, d

    count = [0] * length
    perm = list(range(length))

    for i in range(length - 1, 0, -1):
        d, idx = divmod(idx, math.factorial(i))
        count[i] = d
        perm[:i+1-d], perm[i+1-d:i+1] = perm[d:i+1], perm[:d]  # rotate

    yield perm  # first permutation

    while 1:
        perm[0], perm[1] = perm[1], perm[0]   # rotate
        count[1] += 1
        i = 1
        while count[i] > i:
            count[i] = 0
            i += 1
            if i >= length:
                break
            count[i] += 1
            perm[:i], perm[i] = perm[1:i+1], perm[0]  # rotate

        yield perm


def task_body(parms):
    cdef int maxflips, checksum

    g = PermutationGenerator(parms[0], parms[1])

    maxflips = 0
    checksum = 0
    for i in range(parms[1], parms[2]):
        data = list(g.next() if sys.version_info[0] < 3 else g.__next__())
        f = data[0]
        if f > 0:
            flips = 0
            while f:
                data[:f+1] = data[f::-1]  # reverse
                flips += 1
                f = data[0]
            maxflips = max(maxflips, flips)
            checksum += -flips if i % 2 else flips

    return maxflips, checksum

usage = """usage fannkuchredux number
number has to be in range [3-12]\n"""


def main():
    cdef int length, n, index_max, index_step

    if len(sys.argv) < 2:
        print(usage)
        return 1

    length = int(sys.argv[1])
    if length < 3 or length > MAX_PROBLEM_SIZE:
        print(usage)
        return 2

    n = min(cpu_count(), MAX_CPU_LIMIT)

    index_max = math.factorial(length)
    index_step = (index_max + n-1) // n

    parms = [(length, i, i + index_step) for i in range(0, index_max, index_step)]

    processors = Pool(processes=n)
    res = list(zip(*processors.map(task_body, parms)))

    processors.close()
    processors.join()
    processors.terminate()

    print("%d\nPfannkuchen(%d) = %d" % (sum(res[1]), length, max(res[0])))
    return 0

main()

 make, command-line, and program output logs

Mon, 15 Oct 2018 12:12:08 GMT

MAKE:
make[1]: Vstupuje se do adresáře „/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp“
cp fannkuchredux.cython `echo fannkuchredux.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
cythonize -3 -bi `echo fannkuchredux.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
Compiling /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.pyx because it changed.
[1/1] Cythonizing /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.pyx
running build_ext
building 'fannkuchredux' extension
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher/tmp
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -flto=4 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fstack-protector-strong -fno-plt -fPIC -I/usr/include/python3.7m -c /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.c -o /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.o
gcc -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=4 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/tmpqpic1hga/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.o -L/usr/lib -lpython3.7m -o /home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp/fannkuchredux.cpython-37m-x86_64-linux-gnu.so
make[1]: Opouští se adresář „/home/dundee/workspace/benchmarksgame/bencher/tmp/fannkuchredux/tmp“
4.35s to complete and log all make actions

COMMAND LINE:
/usr/bin/python3 -c "import fannkuchredux" 10

PROGRAM OUTPUT:
73196
Pfannkuchen(10) = 38

Revised BSD license

  Home   Conclusions   License   Play