harmonic.python

View: New views
1 Messages — Rating Filter:   Alert me  

harmonic.python

by Tim Rowe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The program for the harmonic sum benchmark looks to have some addition
operations that can be taken out, and the explicit casts can be taken
out (though I don't know if that's a time saving, as an implicit cast
will still be done).  Here's an amended version that /might/ be
faster.

# http://shootout.alioth.debian.org/
#
# Contributed by Greg Buchholz
# Amended by Tim Rowe to remove O(N) redundant additions,
# O(N) explicit casts and one function call. Might be faster.

import sys

s = 0.0
for i in range(1, int(sys.argv[1]) + 1):
    s = s + 1.0/i
print "%.9f" % s

--
Tim Rowe

_______________________________________________
Shootout-list mailing list
Shootout-list@...
http://lists.alioth.debian.org/mailman/listinfo/shootout-list