How to measure the execution time of this code snippet? | Sololearn: Learn to code for FREE!

+1

How to measure the execution time of this code snippet?

def sumOfN(n): return (n*(n+1))/2

py

6/19/2018 1:20:34 PM

Tincture

2 Answers

New Answer

+2

you can mesure the time execution with using in first line: "start=time.time()" and the final line: "print(time.time()-start)" and it will give you the time ,

0

there's no way to "measure" code execution in milliseconds per se, but if you used big O notation, this code has a time of O(1)