python与matlab速度谁快_Python与MATLAB算法性能比较

我有一个关于代码性能的问题。一个用python实现,一个用MATLAB实现。代码计算时间序列的样本熵(听起来很复杂,但基本上是一堆for循环)。在

我在相对较大的时间序列上运行这两个实现(大约95k+个样本),具体取决于时间序列。MATLAB实现在45秒到1分钟内完成计算。python实现基本上永远不会完成。我把tqdm放到python for循环上,上面的循环仅以~1.85s/it的速度移动,估计完成时间超过50小时(我让它运行了15分钟以上,迭代次数相当一致)。在

输入和运行时示例:

MATLAB(约52秒):a = rand(1, 95000)

sampenc(a, 4, 0.1 * std(a))

Python(目前5分钟,预计49小时):

^{pr2}$

Python实现:# https://github.com/nikdon/pyEntropy

def sample_entropy(time_series, sample_length, tolerance=None):

"""Calculate and return Sample Entropy of the given time series.

Distance between two vectors defined as Euclidean distance and can

be changed in future releases

Args:

time_series: Vector or string of the sample data

sample_length: Number of sequential points of the

你可能感兴趣的:(python与matlab速度谁快_Python与MATLAB算法性能比较)