[Shootout-list] Re: Python Harmonic

Daniel Skiles Daniel Skiles <dskiles@gmail.com>
Tue, 15 Mar 2005 14:43:24 -0500


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

I compared both of my original scripts (attached for convenience, feel
free to yell if it's improper) to the current python harmonic script. 
Both of them are faster than the current script.  The slower of the
two is a little less than twice as fast.  The repeated float() calls
are really slowing the current version down.


On Tue, 15 Mar 2005 07:47:22 -0500, Daniel Skiles <dskiles@gmail.com> wrote:
> 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_532_16333748.1110915804152
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_532_16333748.1110915804152
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_532_16333748.1110915804152--