inheriting a large python code base

R

Rita

hi all,

i just inherited a large python code base and I would like to optimize the
code (run faster). The application is a scientific application so I really
don't understand the internal logic.

Here is what I have done so far, profile (cProfile) and was able to see
where the code was taking the longest time.

I was wondering if anyone else experienced something like this and how they
overcame a problem such a this...what techniques have you used to "optimize"
the code.
 
C

craig

Look at the algorithms and see if there are faster ways. Great advice withthe comments of writing test cases, getting into version control, taking passes through the code with tools, understanding what is slow and why it isconsidered slow. Then you should invest the time to understand the internal logic and the algorithms. Understand the performance O(N log N), O(N^2), O(2^N). See if there are better algorithms that should be used - is therean O(N). Implement that algorithm, test, then compare performance. Finally optimize the coding constructs. Depending on how long your program takes (a few milli-secs, a few secs, a few hours, a few days), optimized codingconstructs may make no measurable difference. Finding better algorithms will. But a better algorithm changing code from 2 milli-secs to 1 milli-secis only useful in specific environments - so it may not be worth your effort. Understand the performance of the code and the environment it is executed in.

That is how I have gone about it type of work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top