Although if a single solution was by far the best under every metric, there wouldn’t be any tradeoffs.
Yes, I debated mentioning this in the post. If a single solution was the best under any metric, then that solution would quickly fade into the background, I think. When I get dressed in the morning, I don’t celebrate the fact that putting on socks before shoes is both easier and more comfortable than the reverse!
A more sensible way to code this would be [...]
I haven’t tested it, but that involves extra multiplication for computing x1 as 1∗x and for multiplying numbers together to get the factorial values. But I haven’t tested it! Maybe I’ll try that today and see if it really is as fast. (The function gets called ~1.7 million times, so even a small difference will be worth keeping the faster code.)
Whoa! I wasn’t expecting so much of a difference. Did you use ```for i in range(...)``` for your loop? That range() call returns an iterator, which I imagine isn’t too fast.
Yes, I debated mentioning this in the post. If a single solution was the best under any metric, then that solution would quickly fade into the background, I think. When I get dressed in the morning, I don’t celebrate the fact that putting on socks before shoes is both easier and more comfortable than the reverse!
I haven’t tested it, but that involves extra multiplication for computing x1 as 1∗x and for multiplying numbers together to get the factorial values. But I haven’t tested it! Maybe I’ll try that today and see if it really is as fast. (The function gets called ~1.7 million times, so even a small difference will be worth keeping the faster code.)
Your right. I did some python. My version took 1.26, yours 0.78 microseconds. My code is just another point on the Pareto boundary.
Whoa! I wasn’t expecting so much of a difference. Did you use ```for i in range(...)``` for your loop? That range() call returns an iterator, which I imagine isn’t too fast.