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
6,000,000211.41111.178,5121203  47% 43% 46% 46%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read chameneos-redux benchmark to see what this program should do.

 notes

 chameneos-redux Cython program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
# contributed by Daniel Nanz 2008-04-10
# 2to3

import sys
import _thread
import time

# colors and matching
creature_colors = ['blue', 'red', 'yellow']

def complement(c1, c2):

    if c1 == c2: return c1
    if c1 == 'blue':
        if c2 == 'red': return 'yellow'
        return 'red'
    if c1 == 'red':
        if c2 == 'blue': return 'yellow'
        return 'blue'
    if c2 == 'blue': return 'red'
    return 'blue'


compl_dict = dict(((c1, c2), complement(c1, c2))
                  for c1 in creature_colors
                  for c2 in creature_colors)


def check_complement(colors=creature_colors, compl=compl_dict):

    for c1 in colors:
        for c2 in colors:
            print('%s + %s -> %s' % (c1, c2, compl[(c1, c2)]))
    print('')


# reporting
def spellout(int n):

    numbers = ['zero', 'one', 'two', 'three', 'four',
               'five', 'six', 'seven', 'eight', 'nine']
    return ' ' + ' '.join(numbers[int(c)] for c in str(n))


def report(input_zoo, met, self_met):

    print(' ' + ' '.join(input_zoo))
    for m, sm in zip(met, self_met):
        print(str(m) + spellout(sm))
    print(spellout(sum(met)) + '\n')


# the zoo
def creature(my_id, venue, my_lock_acquire, in_lock_acquire, out_lock_release):

    while True:
        my_lock_acquire()   # only proceed if not already at meeting place
        in_lock_acquire()   # only proceed when holding in_lock
        venue[0] = my_id    # register at meeting place
        out_lock_release()  # signal "registration ok"


def let_them_meet(int meetings_left, input_zoo,
                  compl=compl_dict, allocate=_thread.allocate_lock):
    # prepare
    cdef int c_no, ci
    c_no = len(input_zoo)
    venue = [-1]
    met = [0] * c_no
    self_met = [0] * c_no
    colors = input_zoo[:]

    in_lock = allocate()
    in_lock_acquire = in_lock.acquire     # function aliases
    in_lock_release = in_lock.release     # (minor performance gain)
    in_lock_acquire()
    out_lock = allocate()
    out_lock_release = out_lock.release
    out_lock_acquire = out_lock.acquire
    out_lock_acquire()
    locks = [allocate() for c in input_zoo]

    # let creatures wild
    for ci in range(c_no):
        args = (ci, venue, locks[ci].acquire, in_lock_acquire, out_lock_release)
        new = _thread.start_new_thread(creature, args)
    time.sleep(0.05)     # to reduce work-load imbalance

    in_lock_release()   # signal "meeting_place open for registration"
    out_lock_acquire()  # only proceed with a "registration ok" signal
    id1 = venue[0]
    while meetings_left > 0:
        in_lock_release()
        out_lock_acquire()
        id2 = venue[0]
        if id1 != id2:
            new_color = compl[(colors[id1], colors[id2])]
            colors[id1] = new_color
            colors[id2] = new_color
            met[id1] += 1
            met[id2] += 1
        else:
            self_met[id1] += 1
            met[id1] += 1
        meetings_left -= 1
        if meetings_left > 0:
            locks[id1].release()  # signal "you were kicked from meeting place"
            id1 = id2
        else:
            report(input_zoo, met, self_met)


def chameneosiate(int n):

    check_complement()
    let_them_meet(n, ['blue', 'red', 'yellow'])
    let_them_meet(n, ['blue', 'red', 'yellow', 'red', 'yellow',
                      'blue', 'red', 'yellow', 'red', 'blue'])
    #print ''


chameneosiate(int(sys.argv[1]))

 make, command-line, and program output logs

Mon, 25 Mar 2019 11:50:52 GMT

MAKE:
make[1]: Vstupuje se do adresáře „/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp“
cp chameneosredux.cython `echo chameneosredux.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
cythonize -3 -bi `echo chameneosredux.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
Compiling /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/chameneosredux.pyx because it changed.
[1/1] Cythonizing /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/chameneosredux.pyx
running build_ext
building 'chameneosredux' extension
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher/tmp
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/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 -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/chameneosredux/tmp/chameneosredux.c -o /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/chameneosredux.o
gcc -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/tmpg9lhclgo/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/chameneosredux.o -L/usr/lib -lpython3.7m -o /home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp/chameneosredux.cpython-37m-x86_64-linux-gnu.so
make[1]: Opouští se adresář „/home/dundee/workspace/benchmarksgame/bencher/tmp/chameneosredux/tmp“
2.86s to complete and log all make actions

COMMAND LINE:
/usr/bin/python3 -c "import chameneosredux" 6000000

PROGRAM OUTPUT NOT CHECKED:
blue + blue -> blue
blue + red -> yellow
blue + yellow -> red
red + blue -> yellow
red + red -> red
red + yellow -> blue
yellow + blue -> red
yellow + red -> blue
yellow + yellow -> yellow

 blue red yellow
3941331 zero
4093312 zero
3965357 zero
 one two zero zero zero zero zero zero

 blue red yellow red yellow blue red yellow red blue
1209397 zero
1307566 zero
1083966 zero
1211933 zero
1178736 zero
1208808 zero
1226634 zero
1245980 zero
1185444 zero
1141536 zero
 one two zero zero zero zero zero zero

Revised BSD license

  Home   Conclusions   License   Play