In [1]:
import smdc_perftests.performance_tests.test_runner as test_runner
import time
import numpy as np


/home/pydev/.virtualenvs/smdc-perftest/local/lib/python2.7/site-packages/pkg_resources.py:991: UserWarning: /home/pydev/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
  warnings.warn(msg, UserWarning)

In [2]:
# use measure decorator to run function multiple times
# and measure execution time of each run
# the returned results gets the name given in 
# the decorator but can be changed later if necessary

@test_runner.measure('experiment', runs=50)
def experiment(sleeptime=0.01):
    time.sleep(sleeptime+np.random.rand(1)*sleeptime)
    
result1 = experiment()
result2 = experiment(0.05)
result2.name = "sleep 0.05"
result3 = experiment(0.011)
result3.name = "sleep 0.011"

# the results can be printed
print result1
print result3


Results experiment
50 runs
median 0.0166 mean 0.0161 stdev 0.0030
sum 0.8067
95%% confidence interval of the mean
upper 0.0170
       |
mean  0.0161
       |
lower 0.0153

Results sleep 0.011
50 runs
median 0.0166 mean 0.0168 stdev 0.0029
sum 0.8392
95%% confidence interval of the mean
upper 0.0176
       |
mean  0.0168
       |
lower 0.0160

In [3]:
# the results can also be compared based on the 95% confidence intervals.

print result1 < result2
print result2 < result1
print result1 < result3


True
False
False

In [4]:
# or then plotted as boxplots
import smdc_perftests.visual as vis
import matplotlib.pyplot as plt
%matplotlib inline

fig, axis = vis.plot_boxplots(result1, result3)
plt.show()


  agg_filter: unknown
  alpha: float (0.0 transparent through 1.0 opaque)         
  animated: [True | False]         
  axes: an :class:`~matplotlib.axes.Axes` instance         
  backgroundcolor: any matplotlib color         
  bbox: rectangle prop dict         
  clip_box: a :class:`matplotlib.transforms.Bbox` instance         
  clip_on: [True | False]         
  clip_path: [ (:class:`~matplotlib.path.Path`,         :class:`~matplotlib.transforms.Transform`) |         :class:`~matplotlib.patches.Patch` | None ]         
  color: any matplotlib color         
  contains: a callable function         
  family or fontfamily or fontname or name: [FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' |                   'monospace' ]         
  figure: a :class:`matplotlib.figure.Figure` instance         
  fontproperties or font_properties: a :class:`matplotlib.font_manager.FontProperties` instance         
  gid: an id string         
  horizontalalignment or ha: [ 'center' | 'right' | 'left' ]         
  label: string or anything printable with '%s' conversion.         
  linespacing: float (multiple of font size)         
  lod: [True | False]         
  multialignment: ['left' | 'right' | 'center' ]         
  path_effects: unknown
  picker: [None|float|boolean|callable]         
  position: (x,y)         
  rasterized: [True | False | None]         
  rotation: [ angle in degrees | 'vertical' | 'horizontal' ]         
  rotation_mode: unknown
  size or fontsize: [size in points | 'xx-small' | 'x-small' | 'small' |                   'medium' | 'large' | 'x-large' | 'xx-large' ]         
  sketch_params: unknown
  snap: unknown
  stretch or fontstretch: [a numeric value in range 0-1000 | 'ultra-condensed' |                   'extra-condensed' | 'condensed' | 'semi-condensed' |                   'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' |                   'ultra-expanded' ]         
  style or fontstyle: [ 'normal' | 'italic' | 'oblique']         
  text: string or anything printable with '%s' conversion.         
  transform: :class:`~matplotlib.transforms.Transform` instance         
  url: a url string         
  variant or fontvariant: [ 'normal' | 'small-caps' ]         
  verticalalignment or va or ma: [ 'center' | 'top' | 'bottom' | 'baseline' ]         
  visible: [True | False]         
  weight or fontweight: [a numeric value in range 0-1000 | 'ultralight' | 'light' |                   'normal' | 'regular' | 'book' | 'medium' | 'roman' |                   'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' |                   'extra bold' | 'black' ]         
  x: float         
  y: float         
  zorder: any number         

In [ ]: