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

Does effective Cython cProfiling imply writing many sub functions?

I am trying to optimize some code with Cython, but cProfile is not providing enough information. To do a good job at profiling, should I create many sub-routines func2, func3,... , func40 ? Note below that i have a function func1 in mycython.pyx,…
HeyWatchThis
  • 21,241
  • 6
  • 33
  • 41
-1
votes
1 answer

Python profile results - Cumulative time of subfunctions doesn't add up to time of function

I am using python profiler for my project. Following is the snippet of the report with print_callees stat output. As can be seen in attached image, total cumulative time taken by ProcessCmd function is 12.893 seconds, but if I try to add the time…
Dharmendra
  • 384
  • 1
  • 5
  • 22
-1
votes
1 answer

Function call is taking 10 seconds

I've profiled my code with cProfile to find bottlenecks and I've found a peculiar one. My code is structured like so: def A1Distance(a_list): #returns something pr = cProfile.Profile() pr.enable() x =…
user3259201
  • 99
  • 2
  • 11
-2
votes
1 answer

how to reduce {time.sleep} time in ansible playbook performance tuning

I am working on ansible playbook performance tuning with the following playbook --- # simplespeedtest.yml - hosts: localhost connection: local gather_facts: false tasks: - command: echo 1 - command: echo 2 - command: echo 30 I…
-3
votes
3 answers

Optimizing for loop in Python to work faster

I am working to optimize Python code. The goal is to take a list of integers and calculate and output how many pairs there are in the list. A pair is considered to be 2 numbers with the difference of K ( 2 in this case) For example: k = 2 list =…
Li Cooper
  • 71
  • 1
  • 2
  • 12
1 2 3
15
16