-2

How to find the algorithm CPU time in python?

what is the function used in python, to find the CPU execution time of the code. (algorithm CPU time, even if several processes are running at a time we should be able to know that how much time does CPU takes to execute only this code)

Pang
  • 9,564
  • 146
  • 81
  • 122

2 Answers2

0

This is a way of doing it. Source: How do I get time of a Python program's execution?

import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
Eddwin Paz
  • 2,842
  • 4
  • 28
  • 48
0

You can use timeit module.

The module provides both a CLI and a callable function.

You may want to consider the distinction between time.time and time.clock

bashrc
  • 4,725
  • 1
  • 22
  • 49