+ 4

Which approach is faster in python?

Suppose that there are 3 ways to solve a problen. How do I know that my code is the fastest for the task Is there a site or a program to rate the code?

21st May 2018, 5:03 AM
onur rr
onur rr - avatar
4 Antworten
+ 4
onur rr Know your algorithm complexity. The more complex an algorithm is the slower it gets, that applies for ALL languages. e.g. A double for loop has complexity of O(n^2). (its very slow) A single for loop has complexity of O(n). (ok speed but not great either) More info on algorithm complexity: http://bigocheatsheet.com https://discrete.gr/complexity/ https://www.sololearn.com/learn/6362/?ref=app
21st May 2018, 6:01 AM
Haris
Haris - avatar
0
Thanks for all the answers. I see time.time and time.clock as answers. Is there a difference between them ?
21st May 2018, 5:34 AM
onur rr
onur rr - avatar
0
It depends on your algorithm
21st May 2018, 6:30 AM
Anthony Perez