Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Python code profiling - Jackson Isaac


Published on

FUDCon 2015, Pune Presentation on Python Code Profiling.

Published in: Technology
  • Be the first to comment

Python code profiling - Jackson Isaac

  2. 2. What Is Profiling?  Analysis of a program to measure the memory used by a certain module, frequency and duration of function calls and the time complexity of the same.  Such profiling tools are termed as ‘profilers’.
  3. 3. Development tools in python  Line_profiler  Memory_profiler  Clone digger
  4. 4. History of line_Profiler  Initial Release v1.0b1 (2008) by Robert Kern.  v1.0b2 (2009) – Fixes related to timing overflow on Windows.  v1.0b3 (2011) – Update Compatibility for newer versions of Cython and IPython.  v1.0 (2014, stable release) – Added compatibility for Python 3.x  Previously supported by kmike’s bitbucket fork of line_profiler.
  5. 5. Installing line_profiler  Using pip – “pip install line_profiler”  From source:  git clone  cd line_profiler  sudo python install (for python 2.7.x)  sudo python3 install (for python3)
  6. 6. Using Line_PRofiler  Adding profiler to the code: @profile def foo(bar): …  Running line_profiler:  -l  python -m line_profiler  python3 -m line_profiler
  7. 7. Live DEMO !
  8. 8. Understanding output  Function : Displays the name of the function which is profiled and its line number.  Line# : Line number of the code in the respective file.  Hits : Number of times the code in the respective line was executed.  Time : Total amount of time spent in executing the line in ‘Timer unit’ (i.e 1e-06s here). May vary from system to system.  Per Hit : The average amount of time spent in executing the line once in Timer Unit.  % Time : The percentage of time spent on that line with respect to the total amount of recorded time spent in the function.  Line Contents : It displays the actual source code.
  9. 9. advantages  Line_profiler helps us to point out which module of our code is running slower than expected by profiling the time taken by each line of code.  Helps in testing large projects, time spent by modules to execute a particular function.  Using this data we can modify and improve our code to build faster and better programs and softwares.
  10. 10. Contact  Website:  Blog:  Email:  Twitter/iJacksonIsaac  LinkedIn/JacksonIsaac   Mozillian/
  11. 11. Thank You