January 2019
Beginner
318 pages
8h 23m
English
As discussed previously, profiling means measuring the execution time of a program. We are going to use the cProfile Python module for profiling a program.
Now, we will write a cprof_example.py script and write the following code in it:
mul_value = 0def mul_numbers( num1, num2 ): mul_value = num1 * num2; print ("Local Value: ", mul_value) return mul_valuemul_numbers( 58, 77 )print ("Global Value: ", mul_value)
Run the program and you will see the output as follows:
student@ubuntu:~$ python3 -m cProfile cprof_example.pyLocal Value: 4466Global Value: 0 6 function calls in 0.000 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 cprof_example.py:1(<module>) ...
Read now
Unlock full access