Why is matlab.engine for python so slow?

I am calling MATLAB functions from Python via MATLAB Engine for Python

, but it is not efficient.

A pure Matlab script works in 30ms

, and a python script in 5.xs

.

Is there a reason? What should I do?


Python code:

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

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


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

      


Python script reslut:

('Time used:', 4.879795798557371)


Matlab runtime:

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

forward | 0.029 s | 0.015 s

+3


source to share


1 answer


The call matlab.engine.start_matlab()

starts a MATLAB session, which will obviously take quite a long time.

So, this is not about Python's inefficiency, but about two different things.



Try moving the line start =

just before the call eng.forward

and see what results you get.

+4


source







All Articles