<p>Reading <a href="https://stackoverflow.com/questions/437/what-is-your-solution-to-the-fizzbuzz-problem">this question</a> I found this as (note the quotation marks) "code" to solve the problem (that's perl by the way). </p>

<pre><code>100,{)..3%!'Fizz'*\5%!'Buzz'*+\or}%n*
</code></pre>

<p>Obviously this is an intellectual example without real (I hope to never see that in real code in my life) implications but, when you have to make the choice, when do you sacrifice code readability for performance? Do you apply just common sense, do you do it always as a last resort? What are your strategies?</p>

<p>Edit: I'm sorry, seeing the answers I might have expressed the question badly (English is not my native language). I don't mean performance vs readability only <strong>after</strong> you've written the code, I ask about before you write it as well. Sometimes you can foresee a performance improvement in the future by making some darker design or providing with some properties that will make your class darker. You may decide you will use multiple threads or just a single one because you expect the scalability that such threads may give you, even when that will make the code much more difficult to understand.</p>

[{'answer_id': 30760, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 3, 'selected': False, 'text': '<p>I always start with the most readable version I can think of.  If performance is a problem, I refactor.  If the readable version makes it hard to generalize, I refactor.</p>\n\n<p>The key is to have good tests so that refactoring is easy.</p>\n\n<p>I view readability as the #1 most important issue in code, though working correctly is a close second.</p>\n'}, {'answer_id': 30762, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 1, 'selected': False, 'text': '<p>Choose readability over performance unless you can prove that you need the performance.</p>\n'}, {'answer_id': 30764, 'author': 'Jason Baker', 'author_id': 2147, 'author_profile': 'https://Stackoverflow.com/users/2147', 'pm_score': 1, 'selected': False, 'text': '<p>I would say that you should only sacrifice readability for performance if there\'s a proven performance problem that\'s significant.  Of course "significant" is the catch there, and what\'s significant and what isn\'t should be specific to the code you\'re working on.</p>\n'}, {'answer_id': 30767, 'author': 'levand', 'author_id': 3044, 'author_profile': 'https://Stackoverflow.com/users/3044', 'pm_score': 3, 'selected': False, 'text': '<p>Readability is most important. With modern computers, only the most intensive routines of the most demanding applications need to worry too much about performance.</p>\n'}, {'answer_id': 30773, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 2, 'selected': False, 'text': '<p>I apply common sense - this sort of thing is just one of the zillion trade-offs that engineering entails, and has few special characteristics that I can see.</p>\n\n<p>But to be more specific, the overwhelming majority of people doing weird unreadable things in the name of performance are doing them prematurely and without measurement.</p>\n'}, {'answer_id': 30782, 'author': 'Marcus Downing', 'author_id': 1000, 'author_profile': 'https://Stackoverflow.com/users/1000', 'pm_score': 2, 'selected': False, 'text': '<p>You should always go for readability first. The shape of a system will typically evolve as you develop it, and the real performance bottlenecks will be unexpected. Only when you have the system running and can see real evidence - as provided by a profiler or other such tool - will the best way to optimise be revealed.</p>\n\n<p>"If you\'re in a hurry, take the long way round."</p>\n'}, {'answer_id': 30787, 'author': 'Jared Updike', 'author_id': 2543, 'author_profile': 'https://Stackoverflow.com/users/2543', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>Programs must be written for people to read, and only incidentally for\n  machines to execute. <br> &nbsp; &mdash; Abelson &amp; Sussman, SICP</p>\n</blockquote>\n\n<p>Well written programs are probably easier to <a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29#When_to_optimize" rel="nofollow noreferrer">profile and hence improve performance</a>.</p>\n'}, {'answer_id': 30789, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 1, 'selected': False, 'text': '<p>"Premature optimization is the root of all evil." - Donald Knuth</p>\n'}, {'answer_id': 30791, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>at times when optimization is necessary, i\'d rather sacrifice compactness and keep the performance enhancement.  perl obviously has some deep waters to plumb in search of the conciseness/performance ratio, but as cute as it is to write one-liners, the person who comes along to maintain your code (who in my experience, is usually myself 6 months later) might prefer something more in the expanded style, as documented here:</p>\n\n<p><a href="http://www.perl.com/pub/a/2004/01/16/regexps.html" rel="nofollow noreferrer">http://www.perl.com/pub/a/2004/01/16/regexps.html</a></p>\n'}, {'answer_id': 30796, 'author': 'akmad', 'author_id': 1314, 'author_profile': 'https://Stackoverflow.com/users/1314', 'pm_score': 6, 'selected': True, 'text': '<p>My process for situations where I think performance may be an issue:</p>\n\n<ol>\n<li>Make it work.</li>\n<li>Make it clear.</li>\n<li>Test the performance.</li>\n<li>If there are meaningful performance issues: refactor for speed.</li>\n</ol>\n\n<p>Note that this does not apply to higher-level design decisions that are more difficult to change at a later stage.</p>\n'}, {'answer_id': 53022, 'author': 'Oskar', 'author_id': 5472, 'author_profile': 'https://Stackoverflow.com/users/5472', 'pm_score': 2, 'selected': False, 'text': "<p>agree with all the above, but also: </p>\n\n<p>when you decide that you want to optimize:</p>\n\n<ol>\n<li>Fix algorithmic aspects before syntax (for example don't do lookups in large arrays)</li>\n<li>Make sure that you prove that your change really did improve things, measure everything</li>\n<li>Comment your optimization so the next guy seeing that function doesn't simplify it back to where you started from</li>\n<li>Can you precompute results or move the computation to where it can be done more effectively (like a db)</li>\n</ol>\n\n<p>in effect, keep readability as long as you can - finding the obscure bug in optimized code is much harder and annoying than in the simple obvious code</p>\n"}, {'answer_id': 53030, 'author': 'rp.', 'author_id': 2536, 'author_profile': 'https://Stackoverflow.com/users/2536', 'pm_score': 1, 'selected': False, 'text': "<p>Readability always wins. Always. Except when it doesn't. And that should be very rarely.</p>\n"}, {'answer_id': 188736, 'author': 'Lev', 'author_id': 7224, 'author_profile': 'https://Stackoverflow.com/users/7224', 'pm_score': 0, 'selected': False, 'text': "<p>There are exceptions to the premature optimization rule. For example, when accessing an image in memory, reading a pixel should not be an out-of-line function. And when providing for custom operations on the image, never do it like this:</p>\n\n<pre><code>typedef Pixel PixelModifierFunction(Pixel);\n\nvoid ModifyAllPixels(PixelModifierFunction);\n</code></pre>\n\n<p>Instead, let external functions access the pixels in memory, though it's uglier. Otherwise, you are sure to write slow code that you'll have to refactor later anyway, so you're doing extra work.</p>\n\n<p>At least, that's true if you know you're going to deal with large images.</p>\n"}, {'answer_id': 1683598, 'author': 'Freddie', 'author_id': 81816, 'author_profile': 'https://Stackoverflow.com/users/81816', 'pm_score': 3, 'selected': False, 'text': '<p>My favorite answer to this question is:</p>\n\n<ol>\n<li>Make it work</li>\n<li>Make it right</li>\n<li>Make it fast</li>\n</ol>\n\n<p>In the scope of things no one gives a crap about readability except the next unlucky fool that has to take care of your code.  However, that being said... if you\'re serious about your art, and this is an art form, you will always strive to make your code the most per formant it can be while still being readable by others.  My friend and mentor (who is a BADASS in every way) once graciously told me on a code-review that "the fool writes code only they can understand, the genius writes code that anyone can understand."  I\'m not sure where he got that from but it has stuck with me.</p>\n\n<p><a href="http://c2.com/cgi/wiki?MakeItWorkMakeItRightMakeItFast" rel="noreferrer">Reference</a></p>\n'}]
['https://Stackoverflow.com/questions/30754', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2695/']