[Tutor] finding square roots
wesley chun
wescpy at gmail.com
Sat Oct 6 01:24:11 CEST 2007
oddly enough, i get different results doing it the "old-fashioned" way:
$ sqrt.py
using **
0.000447034835815
using sqrt()
0.000399112701416
$ sqrt.py
using **
0.00043797492981
using sqrt()
0.000399827957153
$ sqrt.py
using **
0.00043797492981
using sqrt()
0.000402927398682
here's the code snippet... *seems* right to me, but let me know u see any flaws:
from math import sqrt
from time import time
print "using **"
i = 0
now = time()
while i < 1000:
64 ** 0.5
i += 1
print time()-now
print "using sqrt()"
i = 0
now = time()
while i < 1000:
sqrt(64)
i += 1
print time()-now
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Tutor
mailing list