Questions tagged [cprofile]

cProfile is a built-in Python module that describes the run time performance of a program, providing a variety of statistics.

cProfile is a built-in module suitable for profiling Python programs. It's designed as a faster drop-in replacement for the profile implementation. cProfile is implemented as C-Extension which provides less overhead than the pure Python implementation of profile, but it may not be available in all Python implementations.

It can be used in a Python file:

import cProfile
cProfile.run('insert_your_code_to_profile_here')

But also from the command-line, to profile a script:

python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py)

Sources:

230 questions
0
votes
1 answer

How do I pass in a self argument to python cProfile

I am trying to use cProfiling with python. My python project has the following directory structure: my-project ├── src │ ├── lib │ └── app │ └── data │ └── car_sim.py │ │ │ │ ├── ptests │ ├── src │ └── lib…
Saffik
  • 911
  • 4
  • 19
  • 45
0
votes
1 answer

pexpect sendline is too slow

I'm running a subprocess using pexpect. I'm communicating with it off and on via sendline and readline. cProfile indicates my program spends most of its time waiting around for sendline to finish, which is not desired behavior. Python…
0
votes
1 answer

How to use the cProfile mod when the python file takes arguments?

I'm trying to run the cProfile mod on a python program I have. The program has flags and it's currently saying "no such file or directory" when I try to add the flags into the argument. I've tried running python -m cProfile -o resultFile…
avenmia
  • 2,015
  • 4
  • 25
  • 49
0
votes
1 answer

Are python generators faster than nested for loops?

I having some problems trying to understand generators. Do these function's execution time differ when doing the same task? def slow_sum(size): x= 0 for i in range(size): for j in range(size): x += i + j return x def…
SeoFernando
  • 61
  • 2
  • 13
0
votes
0 answers

Python 3: Explanations of the results from cProfile

I am currently trying to improve the speed of my python 3 code is and I ran a cProfile on my code to see what takes up the most time. The problem is that I don't understand what those methods represent from the output. I attached below the output…
Adrian
  • 774
  • 7
  • 26
0
votes
1 answer

mpi4py performance discrepancy after profiling

I have been doing some work with MPI4py arrays, and I recently came across the performance increase after using Scatterv() functions. I have developed a code to inspect the data type of an input object and, in case it is a numeric numpy array, it…
0
votes
1 answer

Run cProfile over a list of files in Python

I've researched other SOF articles about how to do this and have been tinkering with code for a long time now, getting no where. I've also watched YouTube videos about profiling and tried the examples in the cProfile documentation, and they don't…
Debug255
  • 335
  • 3
  • 17
0
votes
1 answer

Cython seems to provide speed-up by reducing the overhead in time profiler rather than the core code?

I was trying to learn and use cython to speed up my personal project but I noticed something weird. Example: Trying out on rbf_network example from http://nealhughes.net/cython1/ import pyximport; pyximport.install() from src.test_cython import…
0
votes
0 answers

How do I profile a class in python, combining profiles?

My goal is to profile just some functions in a while loop, into ONE output. For convenience let's say these functions are in one class. Say I have the following code, just two separate classes accessed in a while loop: class MyClass1: def…
john k
  • 6,268
  • 4
  • 55
  • 59
0
votes
0 answers

conditional profiling with cProfile

Is there any way to do "conditional profiling" with cProfile? I have a method, let's call it readPackets(), which is supposed to take only a few milliseconds at most, but every once in a while it takes 0.5 second or more. (The issue involves…
Jason S
  • 184,598
  • 164
  • 608
  • 970
0
votes
0 answers

Number of python function calls drastically increases when run heroku on the web vs heroku locally?

I've verified that the input files and the code is exactly the same when I run Heroku locally and Heroku on the web. I checked and checked and checked again because I couldn't believe the results. When I run cprofile locally, I get this: PATH:…
S. J.
  • 1,106
  • 1
  • 10
  • 23
0
votes
0 answers

What does cProfile's output "{built-in method load}" mean?

I can't understand what the {built-in method load} output in cProfile means. I know that question was already asked but i saw no real answer. I couldn't find out by myself either. The executed script (Go_IA_vs_IA.py) imports functions from…
Ashargin
  • 498
  • 4
  • 11
0
votes
1 answer

Why query taking more time to execute.

When I execute delete query, It takes more time to execute. I am reading parameters from csv file and the delete data from database using parameters. My delete query is, delete_query = 'delete from app_outage_dfr_correlation_report_exclusions where…
Prafulla
  • 73
  • 2
  • 12
0
votes
1 answer

Fetch current module while running cProfile

I would like to get ahold of my module (to list all function names), even when using cProfile. How can I do that? To clarify I'm using some introspection in my own module, but sys.modules[__main__] does of course not return my own module any more…
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
0
votes
1 answer

Given the output of cProfile on an arbitrary python program, can one reconstruct the original source code?

If I do something like python -m cProfile -o profile.prof myprogram.py Can one reconstruct the source code from have access to profile.prof?
John Allard
  • 3,564
  • 5
  • 23
  • 42