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
50,0000.090.09?2402  10% 90% 22% 10%
50,0000.090.09?2402  100% 0% 11% 11%
50,0000.090.10?2402  0% 100% 10% 0%

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

Read pystone benchmark to see what this program should do.

 notes

 pystone Cython program source code

#! /usr/bin/env python3

"""
"PYSTONE" Benchmark Program

Version:        Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)

Author:         Reinhold P. Weicker,  CACM Vol 27, No 10, 10/84 pg. 1013.

                Translated from ADA to C by Rick Richardson.
                Every method to preserve ADA-likeness has been used,
                at the expense of C-ness.

                Translated from C to Python by Guido van Rossum.

Version History:

                Version 1.1 corrects two bugs in version 1.0:

                First, it leaked memory: in Proc1(), NextRecord ends
                up having a pointer to itself.  I have corrected this
                by zapping NextRecord.PtrComp at the end of Proc1().

                Second, Proc3() used the operator != to compare a
                record to None.  This is rather inefficient and not
                true to the intention of the original benchmark (where
                a pointer comparison to None is intended; the !=
                operator attempts to find a method __cmp__ to do value
                comparison of the record).  Version 1.1 runs 5-10
                percent faster than version 1.0, so benchmark figures
                of different versions can't be compared directly.

"""

LOOPS = 50000

from time import clock

__version__ = "1.1"

cdef int Ident1, Ident2, Ident3, Ident4, Ident5

Ident1 = 1
Ident2 = 2
Ident3 = 3
Ident4 = 4
Ident5 = 5


class Record:

    def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0,
                       IntComp = 0, StringComp = 0):
        self.PtrComp = PtrComp
        self.Discr = Discr
        self.EnumComp = EnumComp
        self.IntComp = IntComp
        self.StringComp = StringComp

    def copy(self):
        return Record(self.PtrComp, self.Discr, self.EnumComp,
                      self.IntComp, self.StringComp)

TRUE = 1
FALSE = 0

cdef void main(int loops):
    pystones(loops)
    print(loops)
    print('OK')


cdef void pystones(int loops):
    Proc0(loops)

cdef int IntGlob
cdef char Char1Glob
cdef char Char2Glob
cdef int* Array1Glob

IntGlob = 0
BoolGlob = FALSE
Char1Glob = b'\0'
Char2Glob = b'\0'
Array1Glob = [0]*51
Array2Glob = list([x[:] for x in [[0]*51]*51])
PtrGlb = None
PtrGlbNext = None


cdef void Proc0(int loops):
    cdef int i

    global IntGlob
    global BoolGlob
    global Char1Glob
    global Char2Glob
    global Array1Glob
    global Array2Glob
    global PtrGlb
    global PtrGlbNext

    starttime = clock()
    for i in range(loops):
        pass
    nulltime = clock() - starttime

    PtrGlbNext = Record()
    PtrGlb = Record()
    PtrGlb.PtrComp = PtrGlbNext
    PtrGlb.Discr = Ident1
    PtrGlb.EnumComp = Ident3
    PtrGlb.IntComp = 40
    PtrGlb.StringComp = b"DHRYSTONE PROGRAM, SOME STRING"
    String1Loc = b"DHRYSTONE PROGRAM, 1'ST STRING"
    Array2Glob[8][7] = 10

    cdef char CharIndex
    cdef int IntLoc1, IntLoc2, IntLoc3, EnumLoc

    for i in range(loops):
        Proc5()
        Proc4()
        IntLoc1 = 2
        IntLoc2 = 3
        String2Loc = b"DHRYSTONE PROGRAM, 2'ND STRING"
        EnumLoc = Ident2
        BoolGlob = not Func2(String1Loc, String2Loc)
        while IntLoc1 < IntLoc2:
            IntLoc3 = 5 * IntLoc1 - IntLoc2
            IntLoc3 = Proc7(IntLoc1, IntLoc2)
            IntLoc1 = IntLoc1 + 1
        Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
        PtrGlb = Proc1(PtrGlb)
        CharIndex = b'A'
        while CharIndex <= Char2Glob:
            if EnumLoc == Func1(CharIndex, b'C'):
                EnumLoc = Proc6(Ident1)
            CharIndex += 1 # chr(ord(CharIndex)+1)
        IntLoc3 = IntLoc2 * IntLoc1
        IntLoc2 = IntLoc3 // IntLoc1
        IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
        IntLoc1 = Proc2(IntLoc1)


def Proc1(PtrParIn):
    PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
    PtrParIn.IntComp = 5
    NextRecord.IntComp = PtrParIn.IntComp
    NextRecord.PtrComp = PtrParIn.PtrComp
    NextRecord.PtrComp = Proc3(NextRecord.PtrComp)
    if NextRecord.Discr == Ident1:
        NextRecord.IntComp = 6
        NextRecord.EnumComp = Proc6(PtrParIn.EnumComp)
        NextRecord.PtrComp = PtrGlb.PtrComp
        NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
    else:
        PtrParIn = NextRecord.copy()
    NextRecord.PtrComp = None
    return PtrParIn

cdef int Proc2(int IntParIO):
    IntLoc = IntParIO + 10
    while 1:
        if Char1Glob == b'A':
            IntLoc = IntLoc - 1
            IntParIO = IntLoc - IntGlob
            EnumLoc = Ident1
        if EnumLoc == Ident1:
            break
    return IntParIO

def Proc3(PtrParOut):
    global IntGlob

    if PtrGlb is not None:
        PtrParOut = PtrGlb.PtrComp
    else:
        IntGlob = 100
    PtrGlb.IntComp = Proc7(10, IntGlob)
    return PtrParOut

cdef void Proc4():
    global Char2Glob
    cdef bint BoolLoc

    BoolLoc = Char1Glob == b'A'
    BoolLoc = BoolLoc or BoolGlob
    Char2Glob = b'B'

cdef void Proc5():
    global Char1Glob
    global BoolGlob

    Char1Glob = b'A'
    BoolGlob = FALSE

cdef int Proc6(int EnumParIn):
    EnumParOut = EnumParIn
    if not Func3(EnumParIn):
        EnumParOut = Ident4
    if EnumParIn == Ident1:
        EnumParOut = Ident1
    elif EnumParIn == Ident2:
        if IntGlob > 100:
            EnumParOut = Ident1
        else:
            EnumParOut = Ident4
    elif EnumParIn == Ident3:
        EnumParOut = Ident2
    elif EnumParIn == Ident4:
        pass
    elif EnumParIn == Ident5:
        EnumParOut = Ident3
    return EnumParOut

cdef int Proc7(int IntParI1, int IntParI2):
    cdef int IntLoc, IntParOut

    IntLoc = IntParI1 + 2
    IntParOut = IntParI2 + IntLoc
    return IntParOut

cdef void Proc8(int* Array1Par, object Array2Par, int IntParI1, int IntParI2):
    global IntGlob
    cdef int IntLoc, IntIndex

    IntLoc = IntParI1 + 5
    Array1Par[IntLoc] = IntParI2
    Array1Par[IntLoc+1] = Array1Par[IntLoc]
    Array1Par[IntLoc+30] = IntLoc
    for IntIndex in range(IntLoc, IntLoc+2):
        Array2Par[IntLoc][IntIndex] = IntLoc
    Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1
    Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
    IntGlob = 5

cdef int Func1(char CharPar1, char CharPar2):
    cdef char CharLoc1, CharLoc2

    CharLoc1 = CharPar1
    CharLoc2 = CharLoc1
    if CharLoc2 != CharPar2:
        return Ident1
    else:
        return Ident2

cdef bint Func2(char* StrParI1, char* StrParI2):
    cdef int IntLoc
    cdef char CharLoc

    IntLoc = 1
    while IntLoc <= 1:
        if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
            CharLoc = b'A'
            IntLoc = IntLoc + 1
    if CharLoc >= b'W' and CharLoc <= b'Z':
        IntLoc = 7
    if CharLoc == b'X':
        return TRUE
    else:
        if StrParI1 > StrParI2:
            IntLoc = IntLoc + 7
            return TRUE
        else:
            return FALSE

cdef bint Func3(int EnumParIn):
    EnumLoc = EnumParIn
    if EnumLoc == Ident3: return TRUE
    return FALSE


import sys


def error(unicode msg):
    print(msg, end=' ', file=sys.stderr)
    print("usage: %s [number_of_loops]" % sys.argv[0], file=sys.stderr)
    sys.exit(100)

cdef int loops, nargs

nargs = len(sys.argv) - 1
if nargs > 1:
    error("%d arguments are too many;" % nargs)
elif nargs == 1:
    try: loops = int(sys.argv[1])
    except ValueError:
        error("Invalid argument %r;" % sys.argv[1])
else:
    loops = LOOPS
main(loops)

 make, command-line, and program output logs

Mon, 15 Oct 2018 12:16:27 GMT

MAKE:
make[1]: Vstupuje se do adresáře „/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp“
cp pystone.cython `echo pystone.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
cythonize -3 -bi `echo pystone.cython | sed 's/cython-..//' | sed 's/.cython//'`.pyx
Compiling /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.pyx because it changed.
[1/1] Cythonizing /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.pyx
running build_ext
building 'pystone' extension
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher/tmp
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone
creating /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/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/pystone/tmp/pystone.c -o /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.o
/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.c: In function ‘__pyx_f_7pystone_Proc0’:
/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.c:2861:8: warning: ‘__pyx_v_EnumLoc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (__pyx_t_2) {
        ^
/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.c:2767:7: note: ‘__pyx_v_EnumLoc’ was declared here
   int __pyx_v_EnumLoc;
       ^~~~~~~~~~~~~~~
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/pystone/tmp/tmpcrefnfv8/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.o -L/usr/lib -lpython3.7m -o /home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp/pystone.cpython-37m-x86_64-linux-gnu.so
make[1]: Opouští se adresář „/home/dundee/workspace/benchmarksgame/bencher/tmp/pystone/tmp“
3.91s to complete and log all make actions

COMMAND LINE:
/usr/bin/python3 -c "import pystone" 50000

PROGRAM OUTPUT:
50000
OK

Revised BSD license

  Home   Conclusions   License   Play