0

I am writing code to count CPU time for a program. The related code is like this:

   with open(script_path, "r") as src:
        scr_contents = src.read()

   proc = subprocess.run(["python", script_path], capture_output = True)

   cup_time = time.process_time()

This script gives me the CPU time for running the whole program of scr_contents.

Now, suppose I have many snippets in this program and I want to get the CPU time for each snippets, what method or function available for this purpose of CPU time counting?

rdas
  • 20,604
  • 6
  • 33
  • 46
Hsin Lee
  • 15
  • 5
  • You should understand that it also takes time for a separate Python process to start up and shut down again for each script that you test. – Karl Knechtel Apr 16 '20 at 03:45
  • Does this answer your question? [How can you profile a Python script?](https://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script) – AMC Apr 16 '20 at 04:11

0 Answers0