MATLAB vs Python Implementation's Speed Difference

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Stephanie Hachem
Posts: 34
Joined: Wed Oct 26, 2016 12:40 pm

MATLAB vs Python Implementation's Speed Difference

Post by Stephanie Hachem » Sun Jul 29, 2018 8:19 am

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

Tags:

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: MATLAB vs Python Implementation's Speed Difference

Post by Thomas Uchida » Sun Jul 29, 2018 3:02 pm

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.

User avatar
Stephanie Hachem
Posts: 34
Joined: Wed Oct 26, 2016 12:40 pm

Re: MATLAB vs Python Implementation's Speed Difference

Post by Stephanie Hachem » Sun Jul 29, 2018 9:11 pm

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

POST REPLY