Skip to content

Instantly share code, notes, and snippets.

@kbarbary
Forked from astrofrog/performance.py
Created June 3, 2012 17:34
Show Gist options
  • Save kbarbary/2864292 to your computer and use it in GitHub Desktop.
Save kbarbary/2864292 to your computer and use it in GitHub Desktop.
photutils performance
import time
import numpy as np
import photutils
from collections import OrderedDict
c = OrderedDict()
name = "Small data, single small aperture"
c[name] = {}
c[name]['dims'] = (20, 20)
c[name]['pos'] = (10., 10.)
c[name]['circ'] = (5.,)
c[name]['circ_ann'] = (5., 6.)
c[name]['elli'] = (5., 2., 0.5)
c[name]['elli_ann'] = (2., 5., 4., 0.5)
c[name]['iter'] = 1000
name = "Big data, single small aperture"
c[name] = {}
c[name]['dims'] = (1000, 1000)
c[name]['pos'] = (500., 500.)
c[name]['circ'] = (5.,)
c[name]['circ_ann'] = (5., 6.)
c[name]['elli'] = (5., 2., 0.5)
c[name]['elli_ann'] = (2., 5., 4., 0.5)
c[name]['iter'] = 1000
name = "Big data, single big aperture"
c[name] = {}
c[name]['dims'] = (1000, 1000)
c[name]['pos'] = (500., 500.)
c[name]['circ'] = (50.,)
c[name]['circ_ann'] = (50., 60.)
c[name]['elli'] = (50., 20., 0.5)
c[name]['elli_ann'] = (20., 50., 40., 0.5)
c[name]['iter'] = 10
name = "Small data, multiple small apertures"
c[name] = {}
c[name]['dims'] = (20, 20)
c[name]['pos'] = (np.random.uniform(5., 15., 1000), np.random.uniform(5., 15., 1000))
c[name]['circ'] = (5.,)
c[name]['circ_ann'] = (5., 6.)
c[name]['elli'] = (5., 2., 0.5)
c[name]['elli_ann'] = (2., 5., 4., 0.5)
c[name]['iter'] = 1
name = "Big data, multiple small apertures"
c[name] = {}
c[name]['dims'] = (1000, 1000)
c[name]['pos'] = (np.random.uniform(250., 750., 1000), np.random.uniform(250., 750., 1000))
c[name]['circ'] = (5.,)
c[name]['circ_ann'] = (5., 6.)
c[name]['elli'] = (5., 2., 0.5)
c[name]['elli_ann'] = (2., 5., 4., 0.5)
c[name]['iter'] = 1
name = "Big data, multiple small apertures, multiple per object"
c[name] = {}
c[name]['dims'] = (1000, 1000)
c[name]['pos'] = (np.random.uniform(250., 750., 1000), np.random.uniform(250., 750., 1000))
c[name]['circ'] = (np.linspace(1., 10., 10).reshape((10, 1)),)
c[name]['iter'] = 1
name = "Big data, multiple big apertures"
c[name] = {}
c[name]['dims'] = (1000, 1000)
c[name]['pos'] = (np.random.uniform(250., 750., 1000), np.random.uniform(250., 750., 1000))
c[name]['circ'] = (50.,)
c[name]['circ_ann'] = (50., 60.)
c[name]['elli'] = (50., 20., 0.5)
c[name]['elli_ann'] = (20., 50., 40., 0.5)
c[name]['iter'] = 1
f = {}
f['circ'] = photutils.aperture_circular
f['circ_ann'] = photutils.annulus_circular
f['elli'] = photutils.aperture_elliptical
f['elli_ann'] = photutils.annulus_elliptical
# Select subset of defined tests and functions to run, to save time.
names_to_run = ["Small data, single small aperture",
"Big data, single small aperture",
"Big data, single big aperture",
"Small data, multiple small apertures",
"Big data, multiple small apertures, multiple per object",
"Big data, multiple small apertures"]
functions_to_run = ['circ', 'circ_ann']
for name in names_to_run:
print "=" * 70
print name
x, y = c[name]['pos']
data = np.ones(c[name]['dims'])
print "%15s " % ("subpixels ="),
for subpixels in [1, 5, 10, 'exact']:
print str(subpixels).center(10) + " ",
print ""
print "-" * 70
t0 = time.time()
for t in functions_to_run:
if t not in c[name]: continue
print "%15s " % t,
for subpixels in [1, 5, 10, 'exact']:
time1 = time.time()
for i in range(c[name]['iter']):
f[t](data, x, y, *c[name][t], subpixels=subpixels)
time2 = time.time()
print "%10.5f " % ((time2 - time1)/c[name]['iter']*1000.),
print ""
t1 = time.time()
print "-" * 70
print 'Real time:', t1 - t0
Note: Times are in ms for a single calculation (except real time which is in s)
======================================================================
Small data, single small aperture
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 0.442 0.496 0.791 0.485
circ_ann 0.398 0.538 1.058 0.806
elli 0.451 0.601 1.044 1.128
elli_ann 0.529 0.750 1.460 1.225
----------------------------------------------------------------------
Real time: 12.2021780014
======================================================================
Big data, single small aperture
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 0.370 0.448 0.679 0.493
circ_ann 0.412 0.654 1.045 0.675
elli 0.452 0.618 1.064 1.131
elli_ann 0.531 0.739 1.417 1.228
----------------------------------------------------------------------
Real time: 11.9569151402
======================================================================
Big data, single big aperture
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 0.830 16.548 65.521 8.165
circ_ann 1.329 28.172 104.839 12.488
elli 1.259 35.536 148.531 50.808
elli_ann 1.530 48.288 201.938 44.846
----------------------------------------------------------------------
Real time: 7.70686602592
======================================================================
Small data, multiple small apertures
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 239.065 316.130 541.385 351.750
circ_ann 256.642 385.747 818.626 544.331
elli 324.661 481.354 898.504 981.842
elli_ann 352.118 582.204 1261.494 1089.414
----------------------------------------------------------------------
Real time: 9.42676615715
======================================================================
Big data, multiple small apertures
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 250.987 319.424 553.005 355.616
circ_ann 256.599 391.445 818.673 550.130
elli 310.647 608.553 955.709 982.566
elli_ann 371.161 584.954 1259.741 1080.193
----------------------------------------------------------------------
Real time: 9.64983105659
======================================================================
Big data, multiple big apertures
subpixels = 1 5 10 exact
----------------------------------------------------------------------
circ 783.926 14467.406 57824.835 5358.977
circ_ann 960.781 24231.674 99426.035 12621.256
elli 1098.681 33718.230 149080.460 51604.902
elli_ann 1434.037 44646.395 196105.284 45405.847
----------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment