Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to calculate the execution time of part of a code in Python

3 Answers

0 votes
import time

start = time.time()

print("time used to execute this print: ")

end = time.time()

print(end - start)






'''
run:

time used to execute this print: 
7.152557373046875e-06

'''

 



answered Apr 30, 2021 by avibootz
0 votes
import time

start = time.perf_counter()

print("time used to execute this print: ")

end = time.perf_counter()

print(end - start)






'''
run:

time used to execute this print: 
7.610302418470383e-06

'''

 



answered Apr 30, 2021 by avibootz
0 votes
import time

start = time.process_time()

print("time used to execute this print: ")

end = time.process_time()

print(end - start)






'''
run:

time used to execute this print: 
1.0453000000000545e-05

'''

 



answered Apr 30, 2021 by avibootz

Related questions

2 answers 239 views
1 answer 136 views
136 views asked Sep 26, 2021 by avibootz
2 answers 134 views
1 answer 293 views
2 answers 256 views
1 answer 227 views
1 answer 203 views
...