Profiling functions

29 views
Skip to first unread message

Shri Keshavinee

unread,
Apr 9, 2021, 8:35:08 AM4/9/21
to sympy
Hi,

I'm writing a proposal on the following project "Classical Mechanics: Efficient Equation of Motion Generation with Python". As a first step, I would like to contribute to it by finding where the functions are getting slower through python profiling and add this as a pull request. But I'm confused about where to implement it. Either adding this file ( profiling functions) in the test folder(sympy/sympy/physics/mechanics/tests/) or in  examples folder(sympy/examples/). Please guide me in choosing the path to implement profiling.

Regards,
Keshav

Oscar Benjamin

unread,
Apr 9, 2021, 9:46:45 AM4/9/21
to sympy
On Fri, 9 Apr 2021 at 13:35, Shri Keshavinee <shrikes...@gmail.com> wrote:
>
> I'm writing a proposal on the following project "Classical Mechanics: Efficient Equation of Motion Generation with Python". As a first step, I would like to contribute to it by finding where the functions are getting slower through python profiling and add this as a pull request. But I'm confused about where to implement it. Either adding this file ( profiling functions) in the test folder(sympy/sympy/physics/mechanics/tests/) or in examples folder(sympy/examples/). Please guide me in choosing the path to implement profiling.

The simplest way to profile something in Python is to make a .py file
that does the thing you want to profile and then run it as:

$ python -m cProfile -s cumulative myscript.py

From ipython you can also use the %prun magic command:

In [1]: M = Matrix([[1, 2], [3, 4]])

In [2]: %prun -s cumulative M**2

%prun has the advantage that it profiles the operation itself rather
than the whole time taken to import sympy and set up variables etc.


Oscar
Reply all
Reply to author
Forward
0 new messages