Python调用c库
from ctypes import cdll,c_float
import time
n = 100000000
dll=cdll.LoadLibrary('./libcuBlasDot2.so')
# 声明一个数组类型
INPUT = c_float * n
# 实例化数组
input = INPUT()
# 为数组赋值(input这个数组是不支持迭代的)
for i in range(n):
input[i] = 1.0
# # 引用C语言的函数
start = time.clock()
dll.dot(input)
end = time.clock()
dura = end - start
print("%s"%dura)
参考:
https://docs.python.org/3.9/library/ctypes.html
https://www.jb51.net/article/155591.htm
来源:CSDN
作者:Claroja
链接:https://blog.csdn.net/claroja/article/details/103878631