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,884 questions

51,810 answers

573 users

How to measure execution time of small code snippets in Python

2 Answers

0 votes
import timeit

print(timeit.timeit('"*".join(str(n) for n in range(500))', number=10000))



'''
run:

1.272735002450645

'''

 



answered Mar 21, 2021 by avibootz
0 votes
import timeit

code='''
for i in range(1000): 
    result = sqrt(i)
'''

print(timeit.timeit(stmt=code, setup="from math import sqrt", number=10000))


 
 
'''
run:
 
1.6891817130381241

'''

 



answered Jul 26, 2022 by avibootz

Related questions

1 answer 292 views
2 answers 255 views
1 answer 226 views
1 answer 177 views
1 answer 178 views
3 answers 198 views
2 answers 137 views
...