Commit 74daf44d authored by Kirill Smelkov's avatar Kirill Smelkov

X compilebench: Add type annotations to pystone_pyx.pyx

This brings in ~8x speedup with tcc and ~14x speedup for gccO2 compared to what
we already had for pystone.py already compiled by Cython.

However Cython compilation time is 1.7x slower and compilation time for gcc*
also raises significantly. For tcc it is "only" 30% more for compilation, but
still the total tcc compilation time is very very small.

name                    old time/op    new time/op    delta
pycompile+pyimport        13.0ms ± 0%    13.0ms ± 0%       ~     (all equal)
pyimport                  12.0ms ± 0%    12.0ms ± 0%       ~     (all equal)
cython/py                  980ms ± 1%     982ms ± 1%       ~     (p=0.666 n=10+10)
cython/pyx                 983ms ± 1%    1692ms ± 1%    +72.13%  (p=0.000 n=9+10)
gcc/compile+link/py        603ms ± 0%     603ms ± 0%       ~     (p=0.766 n=8+10)
gcc/compile+linkO2/py      2.15s ± 0%     2.15s ± 0%       ~     (p=0.749 n=10+10)
gcc/compile+link/pyx       603ms ± 0%    1106ms ± 0%    +83.57%  (p=0.000 n=9+10)
gcc/compile+linkO2/pyx     2.15s ± 0%     3.65s ± 0%    +69.87%  (p=0.000 n=10+10)
tcc/compile+link/py       36.5ms ± 1%    36.0ms ± 0%     -1.37%  (p=0.022 n=10+9)
tcc/compile+link/pyx      36.7ms ± 2%    47.5ms ± 3%    +29.43%  (p=0.000 n=10+10)

name                    old pystone/s  new pystone/s  delta
pystone/py                  227k ± 2%      228k ± 1%       ~     (p=0.182 n=10+9)
pystone/py/gcc              220k ± 3%      221k ± 4%       ~     (p=0.796 n=10+10)
pystone/py/gccO2            433k ± 2%      431k ± 5%       ~     (p=1.000 n=10+10)
pystone/pyx/gcc             221k ± 1%     1855k ± 1%   +737.67%  (p=0.000 n=9+8)
pystone/pyx/gccO2           435k ± 1%     6239k ± 2%  +1335.52%  (p=0.000 n=10+10)
pystone/py/tcc              219k ± 2%      219k ± 0%       ~     (p=0.315 n=10+10)
pystone/pyx/tcc             222k ± 2%     1826k ± 0%   +723.78%  (p=0.000 n=9+9)
parent aa25c782
......@@ -40,24 +40,29 @@ from time import clock
__version__ = "1.1"
[Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6)
cdef int Ident1=1, Ident2=2, Ident3=3, Ident4=4, Ident5=5
class Record:
cdef class Record:
cdef Record PtrComp
cdef int Discr
cdef int EnumComp
cdef int IntComp
cdef str StringComp
def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0,
IntComp = 0, StringComp = 0):
def __init__(self, Record PtrComp = None, int Discr = 0, int EnumComp = 0,
int IntComp = 0, str StringComp = None):
self.PtrComp = PtrComp
self.Discr = Discr
self.EnumComp = EnumComp
self.IntComp = IntComp
self.StringComp = StringComp
def copy(self):
cdef Record copy(self):
return Record(self.PtrComp, self.Discr, self.EnumComp,
self.IntComp, self.StringComp)
TRUE = 1
FALSE = 0
cdef bint TRUE = 1
cdef bint FALSE = 0
def main(loops=LOOPS):
benchtime, stones = pystones(loops)
......@@ -69,14 +74,21 @@ def main(loops=LOOPS):
def pystones(loops=LOOPS):
return Proc0(loops)
IntGlob = 0
BoolGlob = FALSE
Char1Glob = '\0'
Char2Glob = '\0'
Array1Glob = [0]*51
Array2Glob = map(lambda x: x[:], [Array1Glob]*51)
PtrGlb = None
PtrGlbNext = None
cdef int IntGlob = 0
cdef bint BoolGlob = FALSE
cdef char Char1Glob = '\0'
cdef char Char2Glob = '\0'
cdef int[51] _Array1Glob_X
cdef int[:] Array1Glob = _Array1Glob_X
Array1Glob[:] = 0
cdef int[51][51] _Array2Glob_X
cdef int[:,:] Array2Glob = _Array2Glob_X
Array2Glob[:,:] = 0
cdef Record PtrGlb = None
cdef Record PtrGlbNext = None
def Proc0(loops=LOOPS):
global IntGlob
......@@ -105,6 +117,10 @@ def Proc0(loops=LOOPS):
starttime = clock()
cdef int IntLoc1, IntLoc2, IntLoc3
cdef int EnumLoc
cdef char CharIndex
for i in range(loops):
Proc5()
Proc4()
......@@ -121,9 +137,9 @@ def Proc0(loops=LOOPS):
PtrGlb = Proc1(PtrGlb)
CharIndex = 'A'
while CharIndex <= Char2Glob:
if EnumLoc == Func1(CharIndex, 'C'):
if EnumLoc == Func1(CharIndex, <char>'C'):
EnumLoc = Proc6(Ident1)
CharIndex = chr(ord(CharIndex)+1)
CharIndex = CharIndex+1
IntLoc3 = IntLoc2 * IntLoc1
IntLoc2 = IntLoc3 / IntLoc1
IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
......@@ -136,7 +152,7 @@ def Proc0(loops=LOOPS):
loopsPerBenchtime = (loops / benchtime)
return benchtime, loopsPerBenchtime
def Proc1(PtrParIn):
cdef Record Proc1(Record PtrParIn):
PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
PtrParIn.IntComp = 5
NextRecord.IntComp = PtrParIn.IntComp
......@@ -152,8 +168,9 @@ def Proc1(PtrParIn):
NextRecord.PtrComp = None
return PtrParIn
def Proc2(IntParIO):
IntLoc = IntParIO + 10
cdef int Proc2(int IntParIO):
cdef int IntLoc = IntParIO + 10
cdef int EnumLoc = 0 # XXX =0: can be used initialized due to bug in original pystone.py
while 1:
if Char1Glob == 'A':
IntLoc = IntLoc - 1
......@@ -163,7 +180,7 @@ def Proc2(IntParIO):
break
return IntParIO
def Proc3(PtrParOut):
cdef Record Proc3(Record PtrParOut):
global IntGlob
if PtrGlb is not None:
......@@ -173,21 +190,21 @@ def Proc3(PtrParOut):
PtrGlb.IntComp = Proc7(10, IntGlob)
return PtrParOut
def Proc4():
cdef Proc4():
global Char2Glob
BoolLoc = Char1Glob == 'A'
cdef bint BoolLoc = (Char1Glob == 'A')
BoolLoc = BoolLoc or BoolGlob
Char2Glob = 'B'
def Proc5():
cdef Proc5():
global Char1Glob
global BoolGlob
Char1Glob = 'A'
BoolGlob = FALSE
def Proc6(EnumParIn):
cdef int Proc6(int EnumParIn):
EnumParOut = EnumParIn
if not Func3(EnumParIn):
EnumParOut = Ident4
......@@ -206,15 +223,15 @@ def Proc6(EnumParIn):
EnumParOut = Ident3
return EnumParOut
def Proc7(IntParI1, IntParI2):
cdef int Proc7(int IntParI1, int IntParI2):
IntLoc = IntParI1 + 2
IntParOut = IntParI2 + IntLoc
return IntParOut
def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
cdef Proc8(int[:] Array1Par, int[:,:] Array2Par, int IntParI1, int IntParI2):
global IntGlob
IntLoc = IntParI1 + 5
cdef int IntLoc = IntParI1 + 5
Array1Par[IntLoc] = IntParI2
Array1Par[IntLoc+1] = Array1Par[IntLoc]
Array1Par[IntLoc+30] = IntLoc
......@@ -224,7 +241,7 @@ def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
IntGlob = 5
def Func1(CharPar1, CharPar2):
cdef int Func1(char CharPar1, char CharPar2):
CharLoc1 = CharPar1
CharLoc2 = CharLoc1
if CharLoc2 != CharPar2:
......@@ -232,10 +249,11 @@ def Func1(CharPar1, CharPar2):
else:
return Ident2
def Func2(StrParI1, StrParI2):
IntLoc = 1
cdef bint Func2(StrParI1, StrParI2):
cdef int IntLoc = 1
cdef char CharLoc
while IntLoc <= 1:
if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
if Func1((<char*>StrParI1)[IntLoc], (<char*>StrParI2)[IntLoc+1]) == Ident1:
CharLoc = 'A'
IntLoc = IntLoc + 1
if CharLoc >= 'W' and CharLoc <= 'Z':
......@@ -249,7 +267,7 @@ def Func2(StrParI1, StrParI2):
else:
return FALSE
def Func3(EnumParIn):
cdef bint Func3(int EnumParIn):
EnumLoc = EnumParIn
if EnumLoc == Ident3: return TRUE
return FALSE
......
Removing pystone.pyc
Removing pystone_pypyx.so
Removing pystone_pyx.so
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpycompile+pyimport 1 0.013 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkpyimport 1 0.012 s/op
Benchmarkcython/py 1 0.992 s/op
Benchmarkcython/py 1 0.979 s/op
Benchmarkcython/py 1 0.979 s/op
Benchmarkcython/py 1 0.987 s/op
Benchmarkcython/py 1 0.976 s/op
Benchmarkcython/py 1 0.982 s/op
Benchmarkcython/py 1 0.981 s/op
Benchmarkcython/py 1 0.982 s/op
Benchmarkcython/py 1 0.984 s/op
Benchmarkcython/py 1 0.974 s/op
Benchmarkcython/pyx 1 1.689 s/op
Benchmarkcython/pyx 1 1.690 s/op
Benchmarkcython/pyx 1 1.693 s/op
Benchmarkcython/pyx 1 1.686 s/op
Benchmarkcython/pyx 1 1.684 s/op
Benchmarkcython/pyx 1 1.701 s/op
Benchmarkcython/pyx 1 1.692 s/op
Benchmarkcython/pyx 1 1.699 s/op
Benchmarkcython/pyx 1 1.688 s/op
Benchmarkcython/pyx 1 1.693 s/op
Benchmarkpystone/py 1 230803 pystone/s
Benchmarkpystone/py 1 227862 pystone/s
Benchmarkpystone/py 1 228006 pystone/s
Benchmarkpystone/py 1 226811 pystone/s
Benchmarkpystone/py 1 227605 pystone/s
Benchmarkpystone/py 1 228955 pystone/s
Benchmarkpystone/py 1 228692 pystone/s
Benchmarkpystone/py 1 228915 pystone/s
Benchmarkpystone/py 1 224686 pystone/s
Benchmarkpystone/py 1 228180 pystone/s
CC=gcc
Benchmarkgcc/compile+link/py 1 0.601 s/op
Benchmarkgcc/compile+link/py 1 0.603 s/op
Benchmarkgcc/compile+link/py 1 0.602 s/op
Benchmarkgcc/compile+link/py 1 0.605 s/op
Benchmarkgcc/compile+link/py 1 0.602 s/op
Benchmarkgcc/compile+link/py 1 0.602 s/op
Benchmarkgcc/compile+link/py 1 0.605 s/op
Benchmarkgcc/compile+link/py 1 0.604 s/op
Benchmarkgcc/compile+link/py 1 0.602 s/op
Benchmarkgcc/compile+link/py 1 0.605 s/op
Benchmarkpystone/py/gcc 1 223406 pystone/s
Benchmarkpystone/py/gcc 1 222159 pystone/s
Benchmarkpystone/py/gcc 1 224375 pystone/s
Benchmarkpystone/py/gcc 1 218221 pystone/s
Benchmarkpystone/py/gcc 1 217240 pystone/s
Benchmarkpystone/py/gcc 1 221248 pystone/s
Benchmarkpystone/py/gcc 1 220844 pystone/s
Benchmarkpystone/py/gcc 1 212688 pystone/s
Benchmarkpystone/py/gcc 1 225562 pystone/s
Benchmarkpystone/py/gcc 1 224123 pystone/s
Benchmarkgcc/compile+linkO2/py 1 2.154 s/op
Benchmarkgcc/compile+linkO2/py 1 2.155 s/op
Benchmarkgcc/compile+linkO2/py 1 2.154 s/op
Benchmarkgcc/compile+linkO2/py 1 2.152 s/op
Benchmarkgcc/compile+linkO2/py 1 2.154 s/op
Benchmarkgcc/compile+linkO2/py 1 2.157 s/op
Benchmarkgcc/compile+linkO2/py 1 2.152 s/op
Benchmarkgcc/compile+linkO2/py 1 2.151 s/op
Benchmarkgcc/compile+linkO2/py 1 2.151 s/op
Benchmarkgcc/compile+linkO2/py 1 2.148 s/op
Benchmarkpystone/py/gccO2 1 419953 pystone/s
Benchmarkpystone/py/gccO2 1 439344 pystone/s
Benchmarkpystone/py/gccO2 1 434461 pystone/s
Benchmarkpystone/py/gccO2 1 436087 pystone/s
Benchmarkpystone/py/gccO2 1 425876 pystone/s
Benchmarkpystone/py/gccO2 1 437032 pystone/s
Benchmarkpystone/py/gccO2 1 438912 pystone/s
Benchmarkpystone/py/gccO2 1 439116 pystone/s
Benchmarkpystone/py/gccO2 1 431831 pystone/s
Benchmarkpystone/py/gccO2 1 408117 pystone/s
Benchmarkgcc/compile+link/pyx 1 1.108 s/op
Benchmarkgcc/compile+link/pyx 1 1.109 s/op
Benchmarkgcc/compile+link/pyx 1 1.107 s/op
Benchmarkgcc/compile+link/pyx 1 1.108 s/op
Benchmarkgcc/compile+link/pyx 1 1.107 s/op
Benchmarkgcc/compile+link/pyx 1 1.105 s/op
Benchmarkgcc/compile+link/pyx 1 1.106 s/op
Benchmarkgcc/compile+link/pyx 1 1.105 s/op
Benchmarkgcc/compile+link/pyx 1 1.104 s/op
Benchmarkgcc/compile+link/pyx 1 1.106 s/op
Benchmarkpystone/pyx/gcc 1 1.84631e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.86937e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.79565e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.84863e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.85832e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.83851e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.8485e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.75482e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.87392e+06 pystone/s
Benchmarkpystone/pyx/gcc 1 1.85846e+06 pystone/s
Benchmarkgcc/compile+linkO2/pyx 1 3.647 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.658 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.657 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.655 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.654 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.648 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.649 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.672 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.648 s/op
Benchmarkgcc/compile+linkO2/pyx 1 3.660 s/op
Benchmarkpystone/pyx/gccO2 1 6.29089e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.27195e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.2751e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.24454e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.27904e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.222e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.24376e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.14402e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.13422e+06 pystone/s
Benchmarkpystone/pyx/gccO2 1 6.28852e+06 pystone/s
CC=tcc
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.038 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarktcc/compile+link/py 1 0.036 s/op
Benchmarkpystone/py/tcc 1 219283 pystone/s
Benchmarkpystone/py/tcc 1 218130 pystone/s
Benchmarkpystone/py/tcc 1 218993 pystone/s
Benchmarkpystone/py/tcc 1 218747 pystone/s
Benchmarkpystone/py/tcc 1 217537 pystone/s
Benchmarkpystone/py/tcc 1 218471 pystone/s
Benchmarkpystone/py/tcc 1 218670 pystone/s
Benchmarkpystone/py/tcc 1 218044 pystone/s
Benchmarkpystone/py/tcc 1 219547 pystone/s
Benchmarkpystone/py/tcc 1 218365 pystone/s
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.048 s/op
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.049 s/op
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.048 s/op
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.047 s/op
Benchmarktcc/compile+link/pyx 1 0.048 s/op
Benchmarkpystone/pyx/tcc 1 1.82695e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.82715e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.82963e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.82989e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.80343e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.8205e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.81772e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.82615e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.82956e+06 pystone/s
Benchmarkpystone/pyx/tcc 1 1.83056e+06 pystone/s
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment