Friday, May 3, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1108  / 1 Year ago, wed, december 7, 2022, 3:59:24

I want to know whether there is a terminal command that displays the execution time for a python program ? For example using time ./proram_name to display the execution time for C++ program. For example I used g++ hello.cpp -o hello && time ./hello in the terminal to build and see the execution time for the C++ program. And the result was :


Hello world!

real 0m0.009s
user 0m0.000s
sys 0m0.009s

I tried the same as I used in C++. But since there is no object file ie. hello.exe, created so it wasn't that much handy.


More From » command-line

 Answers
5

You can use bash time like this:


time python3 proram_name.py

I would suggest to do this inside python. Basic example from the python manual:


import time

start = time.time()
print("hello")
end = time.time()
print(end - start)

You can use it to time the whole program but also to time specific functions. Far more useful than from bash.


[#245] Thursday, December 8, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shadowoof

Total Points: 293
Total Questions: 112
Total Answers: 137

Location: Burkina Faso
Member since Sun, Nov 21, 2021
3 Years ago
;