找到你要的答案

Q:Why matlab.engine for python is so slow?

Q:为什么matlab.engine Python是如此缓慢?

I'm calling MATLAB Functions from Python via MATLAB Engine for Python, but it is not efficient.

The pure Matlab script runs in 30ms, and the python script in 5.xs.

Is there a reason why? What should I do?


The python code:

import matlab.engine,time
start = time.clock()

eng = matlab.engine.start_matlab()
eng.forward


elapsed = (time.clock() - start)
print("Time used:",elapsed)

The python script reslut:

('Time used:', 4.879795798557371)


The Matlab runtime:

函数名称 | 调用总时间 | 自用时间

forward | 0.029 s | 0.015 s

我调用MATLAB函数Python Python通过Matlab引擎,但它不是有效的。

纯MATLAB脚本运行在30ms,在5.xs Python脚本。

有什么原因吗?我该怎么办?


The python code:

import matlab.engine,time
start = time.clock()

eng = matlab.engine.start_matlab()
eng.forward


elapsed = (time.clock() - start)
print("Time used:",elapsed)

The python script reslut:

(时间:',4.879795798557371)


The Matlab runtime:

函数名称|调用总时间|自用时间

提出了| 0.029 | 0.015

answer1: 回答1:

The call to matlab.engine.start_matlab() starts a MATLAB session, which will obviously take quite some time.

So it is not so much a question of Python being inefficient, but measuring two different things.

Try moving the start = line to just before the eng.forward call and see what results you get.

调用MATLAB引擎。start_matlab()启动一个MATLAB会话,这显然会需要相当长的时间。

所以它是没有这么多的Python效率低的问题,但测量两个不同的东西。

尝试移动起始线就在eng.forward打电话看看你得到什么结果。

python  matlab