Profiling this code shows the bulk of the time is spent on the log operation. Is there another way to write this in Python 3 for more efficiency? Replacing the loop with a list comprehension was actually less efficient and so was map because of lambdas.
def log_total(data):
total = 0.0
log = log(data)
for i in range(10000):
total += log/(i+1)
return total
Thanks!
logfunction?for i in range(1,10001): total += log/i1.42 msecper loop to1.09 msecper loop. That's a pretty big improvement.logfunction the one from themathmodule? If so, I doubt you'll be able to improve on its performance directly (since it's a built-in function implemented in C). Iflogis something you've coded for yourself, then there's might be room for improvement, but you'll have to show its code before we can suggest anything!