Created
March 20, 2017 08:22
-
-
Save darden1/619d8088fa78461f5edb0574c0204b12 to your computer and use it in GitHub Desktop.
Compare the execution speed with Python, Cython and C++ wrapper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import py_test_sum | |
| import cy_test_sum | |
| import cpp_test_sum | |
| n_iter = 10000000 | |
| #--- Python sum | |
| py_ts = py_test_sum.TestSum(n_iter) | |
| tic = time.clock() | |
| py_ts.calc_sum() | |
| toc = time.clock() | |
| print("Python Sum: " + str(py_ts.sum[-1]) + ". Elapsed time: " + str(toc-tic) + " sec.") | |
| #--- Cython sum | |
| cy_ts = cy_test_sum.TestSum(n_iter) | |
| tic = time.clock() | |
| cy_ts.calc_sum() | |
| toc = time.clock() | |
| print("Cython Sum: " + str(cy_ts.sum[-1]) + ". Elapsed time: " + str(toc-tic) + " sec.") | |
| #--- C++ sum | |
| cpp_ts = cpp_test_sum.TestSum(n_iter) | |
| tic = time.clock() | |
| cpp_ts.calc_sum() | |
| toc = time.clock() | |
| print("C++ Sum: " + str(cpp_ts.sum[-1]) + ". Elapsed time: " + str(toc-tic) + " sec.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment