> Anyway, I know the first thing that some of you are going to > say is using eval(). [...] > Which, considering that it is supposed to be exactly 117, > It's darn good. > Unfortunately, it also takes about 10 seconds to do all that. > Any suggestions? Any advice?
On my machine your version takes about 14 seconds. If you replace 'eval(fofx)' with '3*x*x' it takes about 0.7 seconds. Am I allowed to say "don't use eval()" if I'm saying it because it's extremely slow, rather than for security reasons? ;) If the user must be able to enter in the function, then it would be better to evaluate this once and turn it into some sort of function that you can call inside the loop (it's the eval that is so expensive). How to do that depends a lot on how complex the possible functions can be (if they'll only include 'x*+/-' and numbers, for example, it's not so tricky). =Tony.Meyer _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor