I am bringing these two points up now because they directly relate to what is currently happening with the Project Euler problems. They are at a point, still early on, when a simple brute force approach will suffice. Is it possible to whip up an algorithm that will do it in a fraction of the time? Sure. Is it worth it when the amount of time saved will not even be noticeable unless you are taking benchmarks of the apps? Not so much. What about since the whole point of these exercises (at least in my opinion) is to get the ground work laid out showing what can be expected in terms of mathematical difficulty? Even less so.
Many beginners to programming tend to worry far too much about getting a program to run as fast as possible. I have chatted with people that were trying to optimize their code so that the answer is given faster than the current speed of 0.5 SECONDS. This is all well and good if used in a learning context, but if this is used in a production environment, then you just completely wasted your time since the end user won't even notice that change. As with everything in this world there are exceptions, like if your program is going to be run several thousand times in a row, but that is just what needs to be taken into consideration here.
Optimization is a good thing and is fairly important in the high-speed world of today, but it's value fades if improperly used. If there is a tool that you are going to use (on average) once a week for a couple of months and then dispose of it, is there really a point in spending an extra 2 hours to get it milliseconds faster? Following are a couple of things that I look at when making a tool or application to decide what level of optimization is really needed (in no particular order):
- Target Audience
- Personal use
- For my wife or other family member
- For general release
- Frequency of Use
- One time use
- Once a week
- Once a day
- Several times throughout the day
- Several times, one right after the other
- Work/Play
- Am I being payed to make it?
- Time Involved
- Couple of minutes to streamline a couple of loops
- Couple of hours to rewrite main logic
Until next time...
Enjoy!
0 comments:
Post a Comment