Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created Nov 6, 2018
Embed
What would you like to do?
Calls with Cython
import ctypes
import time
from _ctypes import Structure, POINTER, byref
from ctypes import c_int, c_float
import pyximport; pyximport.install()
import multiplication
import numpy as np
a = np.random.rand(2000,2000)
b = np.random.rand(2000,2000)
print("Timing python multiplication:\n")
start = time.time()
python_result = python_multiplication(a, b)
end = time.time()
print(end - start)
print("Timing ctypes C multiplication:\n")
c_result = c_multiplication(a, b)
print("Timing cython multiplication:\n")
start = time.time()
python_result = multiplication.cython_multiplication(a,b)
end = time.time()
print(end - start)
print("Timing numpy multiplication:\n")
start = time.time()
python_result = a * b
end = time.time()
print(end - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment