In [23]:
import pandas as pd
from pandas import Series, DataFrame

In [24]:
#matplotlib.rcdefaults()
matplotlib.rc_file("matplotlibrc.bmh.txt")

In [25]:
process_names=['Normal','Scaling','Gain','Stack','Moving avg','DFT','Matrix mult','Wave 1d']
process=pd.Index(process_names)
python=Series([209,2660,5220,6110,22600,74000,139000,386000],index=process)
numpy_=Series([0.678,6.0,17.7,6.34,2020,285,6.17,273],index=process)
numba=Series([1.02,12.7,24.8,19.7,77.2,74000,329,381000],index=process)
cython=Series([0.801,7.06,18.4,8.87,34.9,2820,334,517],index=process)
fortran=Series([0.579,7.25,23.4,5.75,35.8,219,70.7,102],index=process)

In [26]:
python


Out[26]:
Normal            209
Scaling          2660
Gain             5220
Stack            6110
Moving avg      22600
DFT             74000
Matrix mult    139000
Wave 1d        386000
dtype: int64

In [27]:
names=['Python','Numpy','Numba','Cython','Fortran']

In [28]:
data=DataFrame([python,numpy_,numba,cython,fortran],index=names).T

In [29]:
data


Out[29]:
Python Numpy Numba Cython Fortran
Normal 209 0.678 1.02 0.801 0.579
Scaling 2660 6.000 12.70 7.060 7.250
Gain 5220 17.700 24.80 18.400 23.400
Stack 6110 6.340 19.70 8.870 5.750
Moving avg 22600 2020.000 77.20 34.900 35.800
DFT 74000 285.000 74000.00 2820.000 219.000
Matrix mult 139000 6.170 329.00 334.000 70.700
Wave 1d 386000 273.000 381000.00 517.000 102.000

In [30]:
figure(figsize=[8,6])

styles=['o-','+-','^-','s-','*-']
colors=matplotlib.rcParams['axes.color_cycle']

for col,style,color in zip(data,styles,colors):
    semilogy(data[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)
    
ylabel('Calculation time (ms)',fontsize='large')
gca().set_xticklabels(process_names,rotation=20,fontsize='large')
grid(None,'both')
legend(names,loc='upper left')
savefig('time.tif')
show()



In [31]:
figure(figsize=[8,6])

for col,style,color in zip(data,styles,colors):
    semilogy(data.Python.values/data[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)
    
ylabel('Speedup',fontsize='large')
gca().set_xticklabels(process_names,rotation=20,fontsize='large')
grid(None,'both')
legend(names,loc='upper left')
savefig('speedup.tif')
show()



In [32]:
line_py=array([10,6,9,6,12,10,7,17])
line_np=array([2,2,2,2,6,7,2,13])
line_nb=line_py+1
line_cy=array([11,7,12,7,14,13,8,18])
line_ft=array([6,6,11,10,16,16,6,21])
lines=DataFrame([line_py,line_np,line_nb,line_cy,line_ft],index=names,columns=process).T
lines


Out[32]:
Python Numpy Numba Cython Fortran
Normal 10 2 11 11 6
Scaling 6 2 7 7 6
Gain 9 2 10 12 11
Stack 6 2 7 7 10
Moving avg 12 6 13 14 16
DFT 10 7 11 13 16
Matrix mult 7 2 8 8 6
Wave 1d 17 13 18 18 21

In [33]:
figure(figsize=[8,6])

for col,style,color in zip(lines,styles,colors):
    plot(lines[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)
    
ylabel('Number of lines',fontsize='large')
gca().set_xticklabels(process_names,rotation=20,fontsize='large')
#grid(None,'both')
legend(names,loc='upper left')
savefig('lines.tif')
show()



In [34]:
from scipy.stats.mstats import gmean

In [35]:
data


Out[35]:
Python Numpy Numba Cython Fortran
Normal 209 0.678 1.02 0.801 0.579
Scaling 2660 6.000 12.70 7.060 7.250
Gain 5220 17.700 24.80 18.400 23.400
Stack 6110 6.340 19.70 8.870 5.750
Moving avg 22600 2020.000 77.20 34.900 35.800
DFT 74000 285.000 74000.00 2820.000 219.000
Matrix mult 139000 6.170 329.00 334.000 70.700
Wave 1d 386000 273.000 381000.00 517.000 102.000

In [36]:
arr=[]
for col in data:
    arr.append(data.Python.values/data[col].values)

In [37]:
gm=gmean(arr,axis=1)

In [38]:
figure(figsize=[8,6])
plot(gm[1:],'o-')
ylabel('Speedup (geometrical mean)',fontsize='large')
gca().set_xticks(range(4))
gca().set_xticklabels(names[1:],fontsize='large')

savefig('gmean.tif')
show()



In [38]:


In [54]:
# Gain by scale
size_n=[100,1000,10000]
sizes=pd.Index(size_n)

# in ms
python=Series([50.3,512,5060],index=sizes)
numpy_=Series([0.112,2.41,17.4],index=sizes)
numba=Series([0.192,2.4,23.1],index=sizes)
cython=Series([0.100,1.81,18.1],index=sizes)
fortran=Series([0.115,4.12,20.6],index=sizes)

names=['Python','Numpy','Numba','Cython','Fortran']
gdata=DataFrame([python,numpy_,numba,cython,fortran],index=names).T
gdata


Out[54]:
Python Numpy Numba Cython Fortran
100 50.3 0.112 0.192 0.10 0.115
1000 512.0 2.410 2.400 1.81 4.120
10000 5060.0 17.400 23.100 18.10 20.600

In [56]:
figure(figsize=[8,6])
styles=['o-','+-','^-','s-','*-']
colors=matplotlib.rcParams['axes.color_cycle']

for col,style,color in zip(names,styles,colors):
    loglog(sizes,gdata[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)

xlabel('Number of samples',fontsize='large')
ylabel('Calculation time (ms)',fontsize='large')
legend(names,loc='upper left')
savefig('scale_gain.tif')
show()



In [42]:


In [57]:
# DFT by scale
size_n=[100,1000,10000]
sizes=pd.Index(size_n)

# in ms
python=Series([784,7840,78000],index=sizes)
numpy_=Series([9.38,33.7,285],index=sizes)
numba=Series([786,7870,78000],index=sizes)
cython=Series([29.3,284,2860],index=sizes)
fortran=Series([2.24,21.2,216],index=sizes)

names=['Python','Numpy','Numba','Cython','Fortran']
gdata=DataFrame([python,numpy_,numba,cython,fortran],index=names).T
gdata


Out[57]:
Python Numpy Numba Cython Fortran
100 784 9.38 786 29.3 2.24
1000 7840 33.70 7870 284.0 21.20
10000 78000 285.00 78000 2860.0 216.00

In [58]:
figure(figsize=[8,6])
styles=['o-','+-','^-','s-','*-']
colors=matplotlib.rcParams['axes.color_cycle']

for col,style,color in zip(names,styles,colors):
    loglog(sizes,gdata[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)

xlabel('Number of samples',fontsize='large')
ylabel('Calculation time (ms)',fontsize='large')
legend(names,loc='upper left')
savefig('scale_dft.tif')
show()



In [ ]:


In [68]:
# matmult by scale
size_n=[5,50,500]
sizes=pd.Index(size_n)

# in ms
python=Series([0.165,153,142000],index=sizes)
numpy_=Series([0.00191,0.0119,6.08],index=sizes)
numba=Series([0.00215,0.334,324],index=sizes)
cython=Series([0.0031,0.311,333],index=sizes)
fortran=Series([0.0031,0.105,68.6],index=sizes)

names=['Python','Numpy','Numba','Cython','Fortran']
gdata=DataFrame([python,numpy_,numba,cython,fortran],index=names).T
gdata


Out[68]:
Python Numpy Numba Cython Fortran
5 0.165 0.00191 0.00215 0.0031 0.0031
50 153.000 0.01190 0.33400 0.3110 0.1050
500 142000.000 6.08000 324.00000 333.0000 68.6000

In [83]:
#figure(figsize=[8,6])
#styles=['o-','+-','^-','s-','*-']
#colors=matplotlib.rcParams['axes.color_cycle']

#for col,style,color in zip(names,styles,colors):
#    loglog(sizes,gdata[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)

#xlabel('Matrix dimension',fontsize='large')
#ylabel('Calculation time (ms)',fontsize='large')
#gca().set_xticks([5,50,500])
#gca().set_xticklabels(['5x5','50x50','500x500'])
#xlim([5,500])
#legend(names,loc='upper left')
#savefig('scale_matmul.tif')
#show()

In [ ]:


In [79]:
# matmult by scale
size_n=[10,100,1000]
sizes=pd.Index(size_n)

# in ms
python=Series([1.48,1150,(19.*60+22)*1000],index=sizes)
numpy_=Series([0.00191,0.061,48],index=sizes)
numba=Series([0.00596,2.83,3790],index=sizes)
cython=Series([0.00501,2.69,3410],index=sizes)
fortran=Series([0.00405,0.7,609],index=sizes)

names=['Python','Numpy','Numba','Cython','Fortran']
gdata=DataFrame([python,numpy_,numba,cython,fortran],index=names).T
gdata


Out[79]:
Python Numpy Numba Cython Fortran
10 1.48 0.00191 0.00596 0.00501 0.00405
100 1150.00 0.06100 2.83000 2.69000 0.70000
1000 1162000.00 48.00000 3790.00000 3410.00000 609.00000

In [82]:
figure(figsize=[8,6])
styles=['o-','+-','^-','s-','*-']
colors=matplotlib.rcParams['axes.color_cycle']

for col,style,color in zip(names,styles,colors):
    loglog(sizes,gdata[col].values,style,markersize=10,markerfacecolor='none',markeredgecolor=color,lw=1)

xlabel('Matrix dimension',fontsize='large')
ylabel('Calculation time (ms)',fontsize='large')
gca().set_xticks([10,100,1000])
gca().set_xticklabels(['10x10','100x100','1000x1000'])
#xlim([5,500])
legend(names,loc='upper left')
savefig('scale_matmul.tif')
show()



In [ ]: