Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created March 22, 2013 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelcaraciolo/5219153 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/5219153 to your computer and use it in GitHub Desktop.
from benchy.api import Benchmark, BenchmarkSuite, BenchmarkRunner
import matplotlib.pyplot as plt
common_setup = """
import numpy
X = numpy.random.uniform(1,5,(1000,))
"""
statement = "cosine_distances(X, X)"
setup_bk1 = common_setup + """
import scipy.spatial.distance as ssd
X = X.reshape(-1,1)
def cosine_distances(X, Y):
return 1. - ssd.cdist(X, Y, 'cosine')
"""
benchmark1 = Benchmark(statement, setup_bk1, name="scipy.spatial 0.8.0")
print benchmark1.run()
#{'runtime': {'loops': 10, 'timing': 18.720221519470215, 'repeat': 3, 'success': True, 'units': 'ms'},
# 'memory': {'usage': 0.08203125, 'units': 'MB', 'repeat': 3, 'success': True}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment