This website uses cookies and similar technologies to understand visitors' experiences. By continuing to use this website, you accept our use of cookies and similar technologies,Terms of Use, and Privacy Policy.

Sep 26 2013 - 09:42 AM
How is Your Code Doing ?
Majority of software projects does performance analysis at the final stage , when we have the application ready. Developers and managers tend to forget that performance should be taken as a feature development and not as an end result. Even at the end, we mostly focus on how application as whole is doing and troubleshooting measures might not even involve any code changes. I have experienced that even code changes could improve the performance of application in multiple folds . This blog is specific to performance analysis of Python code. There are various python as well as linux packages available to check the performance of your code . Here are couple of them which I found useful . Linux utilities : 1. Perf - https://perf.wiki.kernel.org/index.php/Tutorial Usage : perf stat python yourprogram.py output : Performance counter stats for 'python myprogram.py': 9.526617 task-clock # 0.957 CPUs utilized 2 context-switches # 0.210 K/sec 0 CPU-migrations # 0.000 K/sec 988 page-faults # 0.104 M/sec cycles stalled-cycles-frontend stalled-cycles-backend instructions branches branch-misses 0.009957910 seconds time elapsed 2. time - http://www.lehman.cuny.edu/cgi-bin/man-cgi?time+1 Usage: $ time python yourprogram.py output: real 0m1.028s user 0m0.001s sys 0m0.003s real - Total time taken by your program to run ( start to finish) user- The amount of CPU time spent in user-mode code (outside the kernel) within the process . sys- refers to the amount of cpu time spent inside kernel specific functions Python Utilities: 1. line_profiler - http://pythonhosted.org/line_profiler/ It is used for line by line profiling the python code. 2. memory_profiler - https://pypi.python.org/pypi/memory_profiler Profiles Memory consumption of a process . 3. objgraph - https://pypi.python.org/pypi/objgraph Figure out the memory leaks in your program
Posted in: Technology|By: Avichal Badaya|1167 Reads