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?
import matlab.engine,time
start = time.clock()
eng = matlab.engine.start_matlab()
eng.forward
elapsed = (time.clock() - start)
print("Time used:",elapsed)
('Time used:', 4.879795798557371)
函数名称 | 调用总时间 | 自用时间
forward | 0.029 s | 0.015 s
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.