Skip to content

Instantly share code, notes, and snippets.

@laing20333
Last active August 29, 2015 14:10
Show Gist options
  • Save laing20333/3914a109cd391d06f037 to your computer and use it in GitHub Desktop.
Save laing20333/3914a109cd391d06f037 to your computer and use it in GitHub Desktop.
#coding=utf-8
import distance_fun
import timeit
import numpy as np
import matplotlib.pyplot as plt
t_python = timeit.Timer("clustering.kp_distance(np.array([1, 2, 4, '住', '公寓']), np.array([2, 2, 2, '商', '公寓']), 0.5)" , "import clustering\nimport numpy as np")
time_python = t_python.timeit(1000000)
print 'python code execution time: ' + str(time_python) + 's'
t_cython = timeit.Timer("distance_fun.kp_distance(np.array([1, 2, 4, '住', '公寓']), np.array([2, 2, 2, '商', '公寓']), 0.5)" , "import distance_fun\nimport numpy as np")
time_cython = t_cython.timeit(1000000)
print 'cython code execution time: ' + str(time_cython) + 's'
print 'SpeedUp: ' + str( (1 - (time_cython / time_python) ) * 100) + str('%')
plt.title('Execution Time between python and cython code')
plt.yticks((0.5,1.5), ('cython', 'python'))
p = plt.bar((0,0), (1,1), width=(time_cython, time_python), bottom=(0,1), color=('r', 'b'))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment