Last active
August 29, 2015 13:56
-
-
Save moorepants/8965993 to your computer and use it in GitHub Desktop.
Timing results for integrating a 2D 2 link pendulum on a cart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moorepants@moorepants-2170p:pydy-code-gen(master)$ ipython | |
Python 2.7.5+ (default, Sep 19 2013, 13:48:49) | |
Type "copyright", "credits" or "license" for more information. | |
IPython 1.1.0 -- An enhanced Interactive Python. | |
? -> Introduction and overview of IPython's features. | |
%quickref -> Quick reference. | |
help -> Python's own help system. | |
object? -> Details about 'object', use 'object??' for extra details. | |
In [1]: import numpy as np | |
In [2]: from pydy_code_gen.tests.models import generate_n_link_pendulum_on_cart_equations_of_motion | |
In [3]: from pydy_code_gen.code import generate_ode_function | |
In [4]: results = generate_n_link_pendulum_on_cart_equations_of_motion(2, False) | |
In [7]: f = generate_ode_function(*results, generator='cython') | |
In [9]: args = {'constants': np.random.random(6)} | |
In [10]: x0 = np.random.random(6) | |
In [12]: from scipy.integrate import odeint | |
In [14]: t = np.linspace(0, 100, 100/0.010) | |
In [15]: %time y = odeint(f, x0, t, (args,)) | |
CPU times: user 919 ms, sys: 897 ms, total: 1.82 s | |
Wall time: 1.37 s | |
In [16]: %prun y = odeint(f, x0, t, (args,)) | |
488646 function calls in 0.956 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
13961 0.302 0.000 0.598 0.000 linalg.py:296(solve) | |
13961 0.150 0.000 0.150 0.000 {multibody_system_p.mass_forcing_matrices} | |
1 0.094 0.094 0.955 0.955 {scipy.integrate._odepack.odeint} | |
13961 0.093 0.000 0.861 0.000 code.py:386(evaluate_ode) | |
13961 0.053 0.000 0.095 0.000 linalg.py:139(_commonType) | |
41883 0.047 0.000 0.047 0.000 {numpy.core.multiarray.array} | |
13961 0.037 0.000 0.037 0.000 {method 'astype' of 'numpy.ndarray' objects} | |
27922 0.032 0.000 0.091 0.000 linalg.py:106(_makearray) | |
27922 0.021 0.000 0.052 0.000 numeric.py:392(asarray) | |
13961 0.018 0.000 0.029 0.000 linalg.py:209(_assertNdSquareness) | |
69805 0.018 0.000 0.018 0.000 {issubclass} | |
13961 0.016 0.000 0.018 0.000 linalg.py:198(_assertRankAtLeast2) | |
13961 0.015 0.000 0.015 0.000 linalg.py:101(get_linalg_error_extobj) | |
41883 0.015 0.000 0.023 0.000 linalg.py:111(isComplexType) | |
27922 0.012 0.000 0.016 0.000 linalg.py:124(_realType) | |
27924 0.008 0.000 0.008 0.000 {getattr} | |
41884 0.006 0.000 0.006 0.000 {len} | |
13961 0.005 0.000 0.005 0.000 {max} | |
13961 0.005 0.000 0.005 0.000 {min} | |
27924 0.005 0.000 0.005 0.000 {method 'get' of 'dict' objects} | |
13961 0.003 0.000 0.003 0.000 {method '__array_prepare__' of 'numpy.ndarray' objects} | |
2 0.001 0.000 0.001 0.000 copy.py:66(copy) | |
1 0.000 0.000 0.956 0.956 odepack.py:19(odeint) | |
1 0.000 0.000 0.956 0.956 <string>:1(<module>) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
In [18]: f = generate_ode_function(*results, generator='lambdify') | |
In [19]: %prun y = odeint(f, x0, t, (args,)) | |
1476461 function calls in 2.349 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
14475 0.372 0.000 0.780 0.000 linalg.py:296(solve) | |
14475 0.312 0.000 0.657 0.000 <string>:1(<lambda>) | |
115800 0.302 0.000 0.302 0.000 {numpy.core.multiarray.array} | |
14475 0.134 0.000 1.653 0.000 code.py:333(mass_forcing_func) | |
28950 0.130 0.000 0.501 0.000 defmatrix.py:244(__new__) | |
14475 0.121 0.000 2.582 0.000 code.py:386(evaluate_ode) | |
28950 0.105 0.000 0.155 0.000 {built-in method __new__ of type object at 0x916e80} | |
1 0.092 0.092 2.673 2.673 {scipy.integrate._odepack.odeint} | |
43425 0.083 0.000 0.182 0.000 shape_base.py:8(atleast_1d) | |
14475 0.060 0.000 0.107 0.000 linalg.py:139(_commonType) | |
43425 0.059 0.000 0.078 0.000 defmatrix.py:290(__array_finalize__) | |
202650 0.057 0.000 0.057 0.000 {math.sin} | |
202650 0.053 0.000 0.053 0.000 {math.cos} | |
130275 0.049 0.000 0.049 0.000 {isinstance} | |
14475 0.046 0.000 0.046 0.000 {numpy.core.multiarray.concatenate} | |
14475 0.044 0.000 0.044 0.000 {method 'astype' of 'numpy.ndarray' objects} | |
14475 0.043 0.000 0.272 0.000 shape_base.py:230(hstack) | |
14475 0.037 0.000 0.065 0.000 {method '__array_prepare__' of 'numpy.ndarray' objects} | |
28950 0.037 0.000 0.113 0.000 linalg.py:106(_makearray) | |
43425 0.033 0.000 0.079 0.000 numeric.py:462(asanyarray) | |
14475 0.021 0.000 0.034 0.000 linalg.py:209(_assertNdSquareness) | |
28950 0.020 0.000 0.066 0.000 numeric.py:392(asarray) | |
72375 0.019 0.000 0.019 0.000 {issubclass} | |
14475 0.017 0.000 0.017 0.000 linalg.py:101(get_linalg_error_extobj) | |
43425 0.017 0.000 0.027 0.000 linalg.py:111(isComplexType) | |
130276 0.017 0.000 0.017 0.000 {len} | |
14475 0.016 0.000 0.019 0.000 linalg.py:198(_assertRankAtLeast2) | |
28950 0.014 0.000 0.019 0.000 linalg.py:124(_realType) | |
28952 0.010 0.000 0.010 0.000 {getattr} | |
43425 0.010 0.000 0.010 0.000 {method 'append' of 'list' objects} | |
14475 0.007 0.000 0.007 0.000 {max} | |
14475 0.006 0.000 0.006 0.000 {min} | |
28952 0.006 0.000 0.006 0.000 {method 'get' of 'dict' objects} | |
2 0.000 0.000 0.000 0.000 copy.py:66(copy) | |
1 0.000 0.000 2.674 2.674 odepack.py:19(odeint) | |
1 0.000 0.000 2.674 2.674 <string>:1(<module>) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
In [20]: t = np.linspace(0, 100, 100/0.001) | |
In [21]: %time y = odeint(f, x0, t, (args,)) | |
CPU times: user 2.33 s, sys: 2.06 s, total: 4.39 s | |
Wall time: 2.2 s | |
In [22]: f = generate_ode_function(*results, generator='cython') | |
In [23]: %time y = odeint(f, x0, t, (args,)) | |
CPU times: user 929 ms, sys: 758 ms, total: 1.69 s | |
Wall time: 847 ms | |
In [24]: results = generate_n_link_pendulum_on_cart_equations_of_motion(10, False) | |
In [25]: f = generate_ode_function(*results, generator='cython') | |
In [26]: f? | |
Type: function | |
String Form:<function evaluate_ode at 0x67c0848> | |
File: /home/moorepants/src/pydy-code-gen/pydy_code_gen/code.py | |
Definition: f(x, t, args) | |
Docstring: | |
Returns the derivatives of the states, i.e. numerically evaluates | |
the right hand side of the first order differential equation(s). | |
x' = f(x, t) | |
Parameters | |
---------- | |
x : ndarray, shape(22,) | |
The current state vector: | |
q0(t), q1(t), q2(t), q3(t), q4(t), q5(t), q6(t), q7(t), q8(t), q9(t), q10(t), u0(t), u1(t), u2(t), u3(t), u4(t), u5(t), u6(t), u7(t), u8(t), u9(t), u10(t) | |
t : float | |
The current time. | |
args : dictionary | |
constants : ndarray, shape(22,) | |
g, m0, l0, m1, l1, m2, l2, m3, l3, m4, l4, m5, l5, m6, l6, m7, l7, m8, l8, m9, l9, m10 | |
specified : ndarray, shape(0,) or a function | |
If this is a function it must be of the form f(x, t), where | |
x is the current state vector and t is the current time and | |
it must return an ndarray of the correct shape. | |
Returns | |
------- | |
dx : ndarray, shape(22,) | |
The derivative of the state vector. | |
In [27]: x0 = np.random.random(22) | |
In [28]: args = {'constants': np.random.random(22)} | |
In [29]: %time y = odeint(f, x0, t, (args,)) | |
CPU times: user 12.1 s, sys: 40.1 s, total: 52.2 s | |
Wall time: 15.5 s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment