Page 1 of 1

MATLAB vs Python Implementation's Speed Difference

Posted: Sun Jul 29, 2018 8:19 am
by gy89
Hi all,

I've been testing the difference between MATLAB and python 2.7 (cygwin) implementations of OpenSim in running forward dynamics of a human arm model. Being careful to use the same files/settings and seemingly equivalent timers in MATLAB and Python, and starting/stopping the timer directly before/after the call to run the forward tool, I've noticed that the Python implementation is notably faster than the MATLAB implementation. For example (averaged over 5 trials for accuracy), when simulating 6 seconds of a forward dynamics simulation, MATLAB takes ~150 s while python takes ~ 85 s. With 8 s, MATLAB takes ~250 s while Python takes ~140 s. That is fine, right? If so, might anyone know what the cause is?

Thank you,

Stephanie Hachem

Re: MATLAB vs Python Implementation's Speed Difference

Posted: Sun Jul 29, 2018 3:02 pm
by tkuchida
That is fine, right?
Yes, a longer simulation should take longer to run; how much longer depends on many things, such as how many integration time steps are taken and, e.g., whether additional memory must be allocated along the way.
might anyone know what the cause is?
It may be difficult to determine how each second of execution time is being used without running some kind of profiler. MATLAB (Java) and Python are different languages, so different performance is expected. If runtime is a concern, you may want to investigate using C++ as well.

Re: MATLAB vs Python Implementation's Speed Difference

Posted: Sun Jul 29, 2018 9:11 pm
by gy89
Hi Dr. Uchida,

I just wanted to be sure that MATLAB time > Python time was expected, or at least not indicative of an error. Interesting; thank you!

Stephanie