How to measure the execution time of this code snippet? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to measure the execution time of this code snippet?

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

19th Jun 2018, 1:20 PM
Tincture
2 Answers
+ 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 ,
31st Jul 2018, 7:01 AM
Sousou
Sousou - avatar
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)
19th Jun 2018, 4:56 PM
hinanawi
hinanawi - avatar