0

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 func1(self):
  #stuff
class MyClass2:
  def func1(self):
  #stuff

count = 0
while count < 100
count += 1

  c1 = MyClass1()
  c1.func1()
  c2 = Myclass2()
  c2.func1()

Obviously these are just examples. In real life each class will have hundreds of methods, there will be many more classes created in the while loop, and count could be up to one million.

I want to profile the functions/methods of class2, not class1, in one nice, readable output (whether file or console). Other Stack Overflow answers do not do this.

Doing profiling a method of a class in Python using cProfile? and How can you profile a script? will print 100+ separate outputs.

how can I profile class methods of my python app? seems to ask the same question but the answer is incomplete.

PyCharm's profile will profile everything, drowning the output I want, and saying the functions I want to profile take 0.000 seconds

Any help is appreciated.

john k
  • 6,268
  • 4
  • 55
  • 59
  • "PyCharm's profile will profile everything, drowning the output I want, and saying the functions I want to profile take 0.000 seconds" what do you mean by this? If so, have you tried wrapping the functions into a new one where you call them like 10000 times? – information_interchange Nov 17 '17 at 03:01
  • Remember there are hundreds of functions, called thousands of times. If a function, cumulative, takes a a tenth of a second, that is a lot. But If I profile it a thousand times, and it takes .0001 each loop, the profile stops at 3 digits, saying it took .000 seconds. Unfortunately the data from the previous classes, the classes I do not have access to, create the data for the classes I want to profile. It's a lot of data, and I can't generate it on my own. – john k Nov 18 '17 at 19:09
  • I have posted an answer in [here](https://stackoverflow.com/a/54115037/9253013) – moshevi Jan 09 '19 at 17:01

0 Answers0