+ 6

Is math.sqrt(x) function faster than pow(x,.5)?

What are the implementations of both the functions? In what way one faster than the other?

25th Jul 2019, 4:42 PM
Chintala Krishna Vamshi
Chintala Krishna Vamshi - avatar
7 Answers
+ 2
sqrt(2) is twice as fast as pow(2, .5) and 2**.5 is ten times faster than sqrt(2): https://code.sololearn.com/cL4cLr3Ju12X
27th Jul 2019, 8:17 AM
Selin Genkur
+ 6
pow is slightly faster, but x**y is the fastest https://code.sololearn.com/c1fRKFT7ibw4/?ref=app
25th Jul 2019, 11:31 PM
Steven M
Steven M - avatar
+ 3
there's also x**.5 Idk which is faster, but it's a good question, you made me curious, one of these days I'll use timeit to find out :)
25th Jul 2019, 9:00 PM
Selin Genkur
+ 1
Ah, answered 3 times(( Many simple construction in python are quickly than difficult ones For example, f and .format(). f is quickly and easier
26th Jul 2019, 1:25 PM
AleksandrNovak
AleksandrNovak - avatar
0
ehh i think: x**5 will be fastest as it directly converted to c.
27th Jul 2019, 9:02 AM
Aralexx
Aralexx - avatar