[Shootout-list] Python Harmonic

Daniel Skiles Daniel Skiles <dskiles@gmail.com>
Tue, 15 Mar 2005 07:47:22 -0500


------=_Part_334_15598087.1110890842398
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hey all,
I have whipped up two python scripts for the Harmonic benchmark.  The
first script (harmonicFunc) is shorter, but takes longer to run.  The
secondScript (harmonicProc) is faster, but uses more lines of code.
Feel free to use either of them to flesh out the benchmarks.

------=_Part_334_15598087.1110890842398
Content-Type: text/plain; name="harmonicFunc.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="harmonicFunc.py"

import sys

n =3D 10000000
if len(sys.argv) > 1:
    n =3D int(sys.argv[1])
partialSum =3D sum([1.0/x for x in xrange(1, n+1)])
print "%.9f" % (partialSum)
------=_Part_334_15598087.1110890842398
Content-Type: text/plain; name="harmonicProc.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="harmonicProc.py"

import sys

n =3D 10000000
if len(sys.argv) > 1:
    n =3D int(sys.argv[1])

partialSum =3D 0
for x in xrange(1, n+1):
    partialSum+=3D 1.0/x

print "%.9f" % (partialSum)
------=_Part_334_15598087.1110890842398--