import systimer reps repslist range(repsfrom math import sqrt def mathmod()for in repslistres sqrt(ireturn res pull out range list time for not math sqrtadds attr fetch time def powcall()for in repslistres pow( return res def powexpr()for in repslistres * return res print(sys versionfor test in (mathmodpowcallpowexpr)elapsedresult timer bestoftotal(test_reps = _reps= print ('% =% (test __name__elapsedresult)following are the test results for the three pythons the and results are roughly twice as fast as and in the prior editiondue largely to faster test machine for each python testedit looks like the math module is quicker than the *expressionwhich is quicker than the pow callhoweveryou should try this with your code and on your own machine and version of python alsonote that python is essentially twice as slow as on this testand pypy is rough order of magnitude ( xfaster than both cpythonsdespite the fact that this is running floating-point math and iterations later versions of any of these pythons might differso time this in the future to see for yourselfc:\codepy - timesqrt py ( :bd afb ebf sep : : [msc bit (amd )mathmod = powcall = powexpr = :\codepy - timesqrt py (defaultapr : : [msc bit (amd )mathmod = powcall = powexpr = :\codec:\pypy\pypy- \pypy timesqrt py ( ffjun : : [pypy with msc bitmathmod = part ivfunctions and generators