Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanHickstein/c1d890ee77362ecf12fa245e54409853 to your computer and use it in GitHub Desktop.
Save DanHickstein/c1d890ee77362ecf12fa245e54409853 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 19 in line 1.
system information: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz16.7.0x86_64Darwin2.7.13
n, basex, basex_bs, direct_C, direct_C_f, direct_Python, direct_Python_f, hansenlaw, hansenlaw_f, linbasex, linbasex_bs, onion_bordas, onion_peeling, onion_peeling_bs, two_point, two_point_bs, three_point, three_point_bs,
101, 0.355, 307.988, 1.073, 0.889, 8.973, 8.731, 2.977, 2.035, 7.562, 0.989, 46.556, 0.075, 0.624, 0.082, 0.829, 0.074, 1.667,
145, 0.853, 806.014, 2.352, 4.204, 18.338, 19.016, 5.344, 4.279, 11.060, 1.706, 121.463, 0.144, 0.845, 0.217, 0.912, 0.540, 3.066,
213, 2.293, 2126.145, 7.182, 5.839, 44.457, 40.238, 11.123, 4.818, 25.126, 3.690, 227.825, 0.344, 2.059, 0.473, 2.236, 0.320, 6.775,
311, 5.762, 5313.606, 35.206, 18.407, 168.899, 121.702, 25.027, 9.351, 91.040, 8.513, 752.732, 1.408, 3.905, 2.547, 5.386, 1.028, 12.482,
453, 29.575, 12562.603, 56.263, 52.017, 500.339, 565.410, 52.389, 16.747, 140.989, 24.919, 1285.347, 2.921, 12.818, 3.203, 11.437, 3.281, 30.384,
661, 83.989, 29769.498, 179.122, 167.475, 1723.701, 2355.122, 88.457, 32.452, 258.163, 39.478, 3013.935, 12.558, 25.534, 8.811, 30.522, 8.137, 88.847,
import numpy as np
import matplotlib.pyplot as plt
filename = 'benchmarks_16.7.0x86_64Darwin_2017-11-06 17h15m49s.csv'
with open(filename,'r') as f:
system = f.readline()[12:]
methods = f.readline().split(', ')[1:-1]
data = np.loadtxt(filename, delimiter=',', skiprows=2, usecols=range(0,len(methods)+1))
n = data[:,0]
fig, ax = plt.subplots()
cnum = 0 # for the colors
for i, meth in enumerate(methods):
times = data[:,i+1]
if '_bs' in meth:
ls = 'dotted'
elif '_f' in meth:
ls = 'dashed'
else:
ls = 'solid'
cnum = cnum+1
ax.plot(n, times, 'o-', color='C%i'%cnum, label=meth, ls=ls)
ax.set_xlabel("Image size")
ax.set_ylabel("Time (ms)")
ax.set_xscale('log')
ax.set_yscale('log')
ax.legend(fontsize='small', frameon=True, loc=4, numpoints=1, labelspacing=0.1)
ax.set_title(system, fontsize='smaller')
ax.axis(xmax=1.0e4, ymin=1.0e-2)
plt.savefig('benchmarks.png', dpi=100)
plt.show()
from __future__ import print_function
import numpy as np
import abel
import sys
import time
import platform
import cpuinfo
maxtime = 100000 # maximum execution time period before method is excluded from timing (milliseconds)
sizes = np.logspace(np.log10(100), np.log10(3000), 10)
n_max_bs = 10000
n_max_slow = 10000
transform_repeat = 2 # for less than 10000
methods = ['basex', 'direct_C', 'direct_Python', 'hansenlaw', 'linbasex','onion_bordas', 'onion_peeling', 'two_point', 'three_point']
select = methods[:] # make a copy
# system information --------------
cpu = cpuinfo.get_cpu_info().get('brand')
os = platform.release() + platform.machine() + platform.system()
pyv = platform.python_version()
system = cpu + os + pyv
print('\n'+system+'\n')
time_string = time.strftime("%Y-%m-%d %Hh%Mm%Ss", time.gmtime())
outfilename = 'benchmarks_' + os + '_' + time_string + '.csv'
print('Saving to: %s\n\n'%outfilename)
outfile = open(outfilename, 'w')
outfile.write('system information: ' + system + '\n')
all_methods = ['basex','basex_bs', 'direct_C', 'direct_C_f', 'direct_Python', 'direct_Python_f', 'hansenlaw', 'hansenlaw_f', 'linbasex', 'linbasex_bs', 'onion_bordas','onion_peeling', 'onion_peeling_bs', 'two_point', 'two_point_bs', 'three_point', 'three_point_bs']
def print_and_write(s): # conveience function to print and write to output file at the same time
print(s, end='')
outfile.write(s)
# write the outputfile header:
print_and_write('n, ')
for method in all_methods:
print_and_write(method+', ')
print_and_write('\n')
for i, n in enumerate(sizes):
n = int( (n//2)*2 + 1 ) # force odd size
if n > 10000:
transform_repeat = 1
try:
res = abel.benchmark.AbelTiming([n], select=select, n_max_bs=n_max_bs,
n_max_slow=n_max_slow, transform_repeat=transform_repeat)
except KeyboardInterrupt:
outfile.close()
sys.exit()
print_and_write('%i, '%n)
for method in select:
iabel = res.iabel[method][0]
print_and_write('% 12.3f, '%iabel)
if method + '_f' in all_methods:
try:
fabel = res.fabel[method][0]
print_and_write('% 12.3f, '%fabel)
except:
fabel = None
print_and_write('% 12.3f, '%0)
else:
fabel = None
if method + '_bs' in all_methods:
try:
bs = res.bs[method+'_bs'][0]
print_and_write('% 12.3f, '%bs)
except:
bs = None
print_and_write('%12.3f, '%0)
else:
bs = None
# drop methods that are taking too long
if iabel > maxtime:
select.remove(method)
elif bs is not None and bs > maxtime:
select.remove(method)
print_and_write('\n')
outfile.flush()
outfile.close()
print('complete!!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment