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
5
votes
2 answers

Performance of library itertools compared to python code

As answer to my question Find the 1 based position to which two lists are the same I got the hint to use the C-library itertools to speed up things. To verify I coded the following test using cProfile: from itertools import takewhile, izip def…
Richard
  • 85
  • 1
  • 7
4
votes
0 answers

Frozen-Flask errors while running cProfile

Building my static site (which uses Flask-Frozen to freeze a Flask app) works fine, but when I tried to profile it with python -m cProfile athena.py, I get the error PermissionError: [Errno 13] Permission…
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75
4
votes
1 answer

cprofile on python module

I am trying to profile a reasonably sized python project using cprofile. I am usually invoking my python app as a module something like: python -m cabon.apps.detector -i input_image.png Now howo can I use cprofile from the command line. I see that…
Luca
  • 10,458
  • 24
  • 107
  • 234
4
votes
2 answers

python: bytecode-oriented profiler

I'm writing a web application (http://www.checkio.org/) which allows users to write python code. As one feedback metric among many, I'd like to enable profiling while running checks on this code. This is to allow users to get a very rough idea of…
bukzor
  • 37,539
  • 11
  • 77
  • 111
4
votes
2 answers

cProfile inside a nested function

I am trying to profile a nested function using cProfile.run. I understand that perhaps cProfile isn't running at the same scope as where I am calling it, but I'm not quite sure what the idiomatic way to achieve this is. Here's an MVCE: def foo(): …
OneRaynyDay
  • 3,658
  • 2
  • 23
  • 56
4
votes
1 answer

Programmatically accessing cProfile data

I need to capture some python profiling data and generate a report. While most of this component runs Python 3.5, to support a couple of legacy modules, we still have part of the system that runs 2.7. In this instance, 3.5 invokes 2.7 via…
Basic
  • 26,321
  • 24
  • 115
  • 201
4
votes
1 answer

cProfile has no method runcall

I'm trying to use cProfile to profile some python code. I believe I need to use cProfile.runcall(), not cProfile.run(), since the method I want to run is of the form self.funct() rather than simply funct(). When I try to use cProfile.runcall,…
PProteus
  • 549
  • 1
  • 10
  • 23
4
votes
0 answers

Getting more precise results from cProfile

My question is very similar to that of Brice Thomas : Python getting meaningful results from cProfile However I could not find a satisfying answer. I'll explain : I get similar results, ie the majority of the time is spent on the functions I use…
Ashargin
  • 498
  • 4
  • 11
4
votes
0 answers

How can I change the decorator function name dynamically to be able to understand cProfile reports?

My problem is the following, 1 - I created a functools.wraps decorator function to log some runtime information. I choose to use functools.wraps because it was supposed to update a wrapper function to look like the wrapped function. So, my decorator…
Axel Borja
  • 3,718
  • 7
  • 36
  • 50
4
votes
2 answers

Is there a high-level profiling module for Python?

I want to profile my Python code. I am well-aware of cProfile, and I use it, but it's too low-level. (For example, there isn't even a straightforward way to catch the return value from the function you're profiling.) One of the things I would like…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
4
votes
0 answers

Interpreting cProfile results: total vs. cumulative time in small function

Most of my Python program is spent in a method called _build_userdbs. I'm using the awesome tool SnakeViz which helps interpreting the results. There's a screenshot below. So right now, in that picture, I'm in _build_userdbs. The big green circle…
Hut8
  • 6,080
  • 4
  • 42
  • 59
4
votes
1 answer

does cProfile profile calls inside threads?

I ran cprofile on a bit of code, which among other things spawns several threads that do most of the work. When I looked at the output of the profiling, I see no logging of all the functions that were called inside the threads. I am sure they were…
olamundo
  • 23,991
  • 34
  • 108
  • 149
4
votes
1 answer

What does {built-in method select} do in Python 3?

When profiling my application using cProfile and pstats, one of the rows reads: ncalls tottime percall cumtime percall filename:lineno(function) 6 2.940 0.490 2.940 0.490 {built-in method select} What does this method do and…
Tregoreg
  • 18,872
  • 15
  • 48
  • 69
4
votes
1 answer

On python with numpy/scipy len() cProfile result

Possible Duplicate: How can you profile a Python script? I have using cProfile to find out what method spent me most of the time on my python code, here is an output after sorting for "percall": I found that the method len() spent me most of the…
wh0
  • 510
  • 1
  • 6
  • 19
3
votes
2 answers

cProfile seems to override the normal value of `__file__`, how adapt?

I have a program that relies on the __file__ built-in global to provide the path to data associated with the program, as in path_to_stuff = os.path.join(os.path.dirname(__file__),'stuff'). The problem is that when I run this with python -m cProfile…
user405
  • 579
  • 7
  • 13