In general, the most important solution to a problem is going to be the one that actually exists and is valid for the cases as they exist for your problem. In other-words, avoid premature optimization until such time that you actually know you have inefficient code, or efficient code that needs to be faster.
Also, don't forget that the best solution for your application may not be the general case solution. Case and point, a couple years back a professor gave our class a problem in which we were to print the first 10 numbers of a given type (sorry, my memory fails me as to the type, but it was one of the more unusual number classes) and we were given a test to check to ensure that the number was the given type. This was the extent of problem we were given and we were told it was due the next day with the most efficient solution receiving full credit. The following lecture the professor summarized the results:
- Some students used a simple loop and the formula provided to check to ensure the numbers were correct and displayed them, slow but got the job done, O(n^3).
- Other students did their research and found a formula that did a better job of checking to ensure that a given number was valid, these programs ran much faster, O(n^2).
- One student used the slow formula to generate the values and then copied them into a constant array in their code and display the contents of that, O(n).
The final solution was judged the most efficient by the professor. Turns out that the problem was actually an exercise in fully understanding the problem and not just going out and finding the most efficient solution.
The point of the above is that when it comes to finding an efficient solution a problem it is generally better to spend the time to make sure you really understand what the problem is before going off and writing code, or attempting to optimize code. If you can store a set of reference values in a constant array then you are better off doing that from a performance standpoint than trying to write some fancy algorithm.
Likewise, don't forget that for most applications, the only people that tend to see inefficient code (when it is not needlessly inefficient!) are the developers themselves. If you write clean code that only does exactly what it needs to do then odds are that the majority of the time the users aren't going to notice performance issues when working with your program and when they do just optimize the parts that they mention to you.