profiling

How do I use line_profiler (from Robert Kern)?

How do I use line_profiler (from Robert Kern)? Question: I have tried using the line_profiler module for getting a line-by-line profile over a Python file. This is what I’ve done so far: 1) Installed line_profiler from pypi by using the .exe file (I am on WinXP and Win7). Just clicked through the installation wizard. 2) …

Total answers: 6

Calculate summary statistics of columns in dataframe

Calculate summary statistics of columns in dataframe Question: I have a dataframe of the following form (for example) shopper_num,is_martian,number_of_items,count_pineapples,birth_country,tranpsortation_method 1,FALSE,0,0,MX, 2,FALSE,1,0,MX, 3,FALSE,0,0,MX, 4,FALSE,22,0,MX, 5,FALSE,0,0,MX, 6,FALSE,0,0,MX, 7,FALSE,5,0,MX, 8,FALSE,0,0,MX, 9,FALSE,4,0,MX, 10,FALSE,2,0,MX, 11,FALSE,0,0,MX, 12,FALSE,13,0,MX, 13,FALSE,0,0,CA, 14,FALSE,0,0,US, How can I use Pandas to calculate summary statistics of each column (column data types are variable, some columns have no information …

Total answers: 3

Interactive Python: cannot get `%lprun` to work, although line_profiler is imported properly

Interactive Python: cannot get `%lprun` to work, although line_profiler is imported properly Question: Problem Most iPython “magic functions” work fine for me right off the bat: %hist, %time, %prun, etc. However, I noticed that %lprun could not be found with iPython as I’d installed it originally. Attempt to Resolve I then discovered that I should …

Total answers: 2

What is the reliable method to find most time consuming part of the code?

What is the reliable method to find most time consuming part of the code? Question: Along my source code I try to capture and measure the time release of a segment in Python. How can I measure that segment pass time in a convenient way with good precision? Asked By: erogol || Source Answers: Use …

Total answers: 1

How to measure time taken between lines of code in python?

How to measure time taken between lines of code in python? Question: So in Java, we can do How to measure time taken by a function to execute But how is it done in python? To measure the time start and end time between lines of code? Something that does this: import some_time_library starttime = …

Total answers: 11

Why does Python code run faster in a function?

Why does Python code run faster in a function? Question: def main(): for i in xrange(10**8): pass main() This piece of code in Python runs in (Note: The timing is done with the time function in BASH in Linux.) real 0m1.841s user 0m1.828s sys 0m0.012s However, if the for loop isn’t placed within a function, …

Total answers: 3

Sort cProfile output by percall when profiling a Python script

Sort cProfile output by percall when profiling a Python script Question: I’m using python -m cProfile -s calls myscript.py python -m cProfile -s percall myscript.py does not work. The Python documentation says “Look in the Stats documentation for valid sort values.”: http://docs.python.org/library/profile.html#module-cProfile, which I cannot find. Asked By: Brandon O'Rourke || Source Answers: -s only …

Total answers: 1

Tracking *maximum* memory usage by a Python function

Tracking *maximum* memory usage by a Python function Question: I want to find out what the maximum amount of RAM allocated during the call to a function is (in Python). There are other questions on SO related to tracking RAM usage: Which Python memory profiler is recommended? How do I profile memory usage in Python? …

Total answers: 8

cProfile for Python does not recognize Function name

cProfile for Python does not recognize Function name Question: I have a function in an app called email which I want to profile. When I try to do something like this, it blows up from django.core.management import BaseCommand import cProfile class Command(BaseCommand): def handle(self, *args, **options): from email.modname import send_email cProfile.run(‘send_email(user_id=1, city_id=4)’) When I run …

Total answers: 1

cProfile saving data to file causes jumbles of characters

cProfile saving data to file causes jumbles of characters Question: I am using cProfile on a module named bot4CA.py so in the console I type: python -m cProfile -o thing.txt bot4CA.py After the module runs and exits, it creates a file named thing.txt and when I open it, there is some information there, and the …

Total answers: 3