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
2
votes
1 answer

Python cProfile results do not appear to add up

I have attached a screenshot of the cProfile results of a Python script. I know the second line refers to a geoprocessing function in the arcpy site-package. However, I am unclear what the first line refers to: C:\Program Files …
Borealis
  • 8,044
  • 17
  • 64
  • 112
2
votes
2 answers

timeit eats return value

I want to measure execution time of a function on the cheap, something like this: def my_timeit(func, *args, **kwargs): t0 = time.time() result = func(*args, **kwargs) delta = time.time() - t0 return delta, result def foo(): …
wim
  • 338,267
  • 99
  • 616
  • 750
2
votes
0 answers

What is {built-in method load} when I run cProfile in Python?

I'm running cProfile to benchmark my Django application. The relevant lines look like this: ncalls tottime percall cumtime percall filename:lineno(function) 3 0.027 0.009 0.027 0.009 {built-in method load} 149 0.004 0.000…
ldinh
  • 113
  • 1
  • 5
2
votes
3 answers

App Engine WSGI middleware profiler

I have a Django application which I decided to port to Google App Engine. I decided to use NDB as my database and have ported all the models (including django user). After one week of reading through the documentation (the App Engine documentation…
andrei
  • 877
  • 8
  • 18
1
vote
1 answer

How to use "dump_pstats" properly to retrieve the sorted data of the "cProfile" into "txt" file?

As the title indicate I have this issue of retrieving those information from dump_stats properly. Without further ado here is my simple code. Code import cProfile import pstats def fun_to_profile(): ... code to be profilled ... profiler =…
Lambda
  • 33
  • 6
1
vote
1 answer

Increase Output Resolution of Python cProfile (More Resolution in Output Required)

I am profiling a simple Python function such as def prof_func(): x = 100 y = 100 a = np.random.rand(x,y) c = signal.convolve2d(a, a, boundary='symm', mode='same') using cProfile but the times I get out only have a resolution of…
1
vote
1 answer

runsnake fails in ubuntu with error in squaremap

When I start runsnake with $ runsnake test.profile the window opens, but with no graphics and no source code (only the list of calls, etc. is present). On the console, I see the following error message: 11:18:17: Debug: Adding duplicate image…
1
vote
0 answers

Can the Pycharm profiler, cProfile, be set to profile only a couple of lines of code and not the whole script?

Pycharm's standard profiler for python is cProfile or Yappi. While using cProfile in Pycharm, you don't have to change or edit your code, you just have to use the graphical interface and press the profile button. However, whenever I do this, Pycharm…
1
vote
0 answers

How to pass variables to nested functions in cProfile's runctx()

I'm trying to profile some code, but it has nested function calls. It looks something like this: ### user.py class MyFlaskAPI: def get(self): page = 1 pagesize = 100 offset = 0 user = get_user() results =…
Klutch27
  • 167
  • 2
  • 9
1
vote
0 answers

Get the name of the class derived from cProfile statistics

I am trying to retrieve the class name of an code object in python. These code objects are the outputs of the statistics of a cProfile. An example of what I am trying to do below: from cProfile import Profile from typing import Any class foo: …
1
vote
0 answers

Numba entries in cprofile

When profiling code with cprofile, I noticed that there appear a lot of numba entries referring to the numba compiler. I know that the computation time is high at the first run of the script due to compiling. The attached screenshot however shows…
D Cro
  • 85
  • 6
1
vote
0 answers

How to interpret cProfile results of PuLP

I fear I am a bit in over my head. I have profiled a Mixed Integer Problem (MIP) with cProfile and gprof2dot. The MIP is implemented via the pulp library. The MIP problem is solvable, which I tested on smaller problems. I profiled the MIP on a…
6'38''4
  • 23
  • 5
1
vote
0 answers

Dictionary creation taking way longer on my coworkers computer

My coworker asked me to look at his code and try to make it go faster. The goal of the code is to read some large excel sheets, do some operations with the data and then write to an excel sheet. I realized the main problem in the code was the…
benr
  • 45
  • 6
1
vote
1 answer

Python cProfile: Is it possible for pyo file

I am beginner to Python and trying to invoke the cProfile through command line i.e. python -m cProfile -o ./temp/PROFILE.log myScript.pyo But it throws an error message stating that SyntaxError: Non-ASCII character '\xb3' in file myScript.pyo on…
Kashif
  • 1,238
  • 10
  • 15