<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Endlessly Curious &#187; Optimisation</title>
	<atom:link href="http://www.endlesslycurious.com/tag/optimisation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.endlesslycurious.com</link>
	<description>Programming, Productivity &#38; Software Development.</description>
	<lastBuildDate>Mon, 09 Jan 2012 09:00:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Preemptive optimisation: do not do it!</title>
		<link>http://www.endlesslycurious.com/2008/11/26/preemptive-optimisation-do-not-do-it/</link>
		<comments>http://www.endlesslycurious.com/2008/11/26/preemptive-optimisation-do-not-do-it/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 09:00:47 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Optimisation]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=837</guid>
		<description><![CDATA[Yesterday I wrote about optimisation work flow and in this post I will be discussing why you should not preemptively optimise your program&#8217;s source code.  You may wonder what could possibly be wrong with preemptively optimising the source code, it just makes your program faster right?  And that is the trap: while it does make [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I wrote about optimisation work flow and in this post I will be discussing why you should not preemptively optimise your program&#8217;s source code.  You may wonder what could possibly be wrong with preemptively optimising the source code, it just makes your program faster right?  And that is the trap: while it does make your program faster, if you do not measure the programs performance relative to your performance goals you are effectively taking a shot in the dark with very little real likelihood of hitting your (performance) mark and a real likelihood of unintended consequences in terms of the quality, understandability, complexity and bug count in your program&#8217;s source code.</p>
<p>For example, it faster on the CPU you are targeting to compare an integer to zero than to compare an integer to another integer.  Therefore you have decided to write all your loops so they count down to zero instead of the normal approach of counting up from zero.  This will save you a few cycles per iteration of your loop, but have you considered:</p>
<ul>
<li>Counting down and not up in a loop is not conventional in most programming languages and may result in you making math errors which can result in hard to track down bugs in your loop control logic or code inside your loop.</li>
<li>Pointer arithmetic in languages like C/C++ is hard enough when counting up (e.g, pObj++) but counting down is even harder to understand as it is so incredibly rarely done and requires extra pointer math to set up.</li>
<li>The programmer that comes after you to develop or maintain the source code may not realise you are counting down and not up in your loop and then implement functionality that relies on your loop counting up which would again cause bugs and confusion.</li>
<li>That despite your loop being invoked for thousands or millions of iterations, your loop&#8217;s control logic is no where near as expensive in terms of CPU operations as function call X that comes right in the middle of your loop which costs <em>millions</em> of cycles by itself every iteration!</li>
<li>That it is almost unheard of for loop control logic to be an issue performance wise even when it is in tightest inner loops.</li>
<li>That most optimising compilers are perfectly able to make this optimisation for you during compilation on your target platform with none of the above programmer confusion?</li>
</ul>
<p>My advice here is never optimise without measuring first: as at best you will save a few CPU cycles where it really does not matter at the cost of making your source more complex and harder to understand and at worse you will add subtle bugs to your program and make the source code more complex and harder to understand or maintain!  I have lost count now of how many times I&#8217;ve tracked subtle bugs in programs down to programmers making preemptive optimisations without first measuring to see if any optimisation is required and if the extra level of complexity introduced by the optimisation is a desirable trade off.</p>
<p>Occasionally there will be an exception to this rule but in general if you are going to optimise something should always measure first and then optimise only if it is nessessary.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/11/26/preemptive-optimisation-do-not-do-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimisation Workflow</title>
		<link>http://www.endlesslycurious.com/2008/11/25/optimisation-workflow/</link>
		<comments>http://www.endlesslycurious.com/2008/11/25/optimisation-workflow/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 09:00:25 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Optimisation]]></category>
		<category><![CDATA[Visualisation]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=828</guid>
		<description><![CDATA[I believe the key to optimising any program is measurement: not writing l33t code which seems to be what a lot of programmers think optimisation is!  The optimisation process is all about finding the slow parts of your program and speeding those slow parts up by refactoring your source code to meet your target performance [...]]]></description>
			<content:encoded><![CDATA[<p>I believe the key to <a href="http://en.wikipedia.org/wiki/Optimization_(computer_science)">optimising</a> any program is measurement: not writing <a href="http://en.wikipedia.org/wiki/Leet"><em>l33t</em></a> code which seems to be what a lot of programmers think optimisation is!  The optimisation process is all about finding the slow parts of your program and speeding those slow parts up by <a href="http://www.refactoring.com/sources.html">refactoring</a> your source code to meet your target performance goals.  Without measuring the code or having target performance goals optimisation is a waste of time: as programmers are very bad at guessing where the slow parts of the program are and very good at optimising pieces of the program that do not need it.</p>
<p><img class="aligncenter size-full wp-image-829" title="Optimisation Workflow" src="http://www.endlesslycurious.com/wp-content/uploads/2008/11/optimisationflow.jpg" alt="" width="480" height="367" /></p>
<p>This diagram emphasises the importance of measurement in the optimisation process: you cannot begin the process, evaluate your optimisations, even discard your optimistations or honestly finish the process without first measuring the program performance versus your target performance.  As I have mentioned <a href="http://www.endlesslycurious.com/2008/10/07/optimisation-effort-vs-performance-gain/">before</a> the initial optimisations to a program tend to yeild larger returns and then returns drop off until much more time is invested. These initial easy optimisations are not usually the sort of changes new programmers expect: they expect sexy <em>l33t</em> code like inline assembler for big performance wins, not tweaking compiler flags or removing calls to a pure virtual method on a base object in an inner loop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/11/25/optimisation-workflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimisation effort Vs. Performance Gain</title>
		<link>http://www.endlesslycurious.com/2008/10/07/optimisation-effort-vs-performance-gain/</link>
		<comments>http://www.endlesslycurious.com/2008/10/07/optimisation-effort-vs-performance-gain/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 08:00:49 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Optimisation]]></category>
		<category><![CDATA[Visualisation]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=414</guid>
		<description><![CDATA[This may seem strange but in my experience it is true that the first few optimisation efforts on any un-optimised system tend to yeild high returns for low effort e.g, tweaking some compiler or linker settings in a few minutes.  Further medium term efforts tend to suffer from diminishing returns e.g, rewriting critical sections in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-415" title="Optimisation Effort Vs Performance Gain" src="http://www.endlesslycurious.com/wp-content/uploads/2008/10/effortgainoptimisation.jpg" alt="" width="320" height="201" /></p>
<p style="text-align: center;">This may seem strange but in my experience it is true that the first few optimisation efforts on any un-optimised system tend to yeild high returns for low effort e.g, tweaking some compiler or linker settings in a few minutes.  Further medium term efforts tend to suffer from diminishing returns e.g, rewriting critical sections in assembler over a few days for a few percent improvment.  Finally large scale optimisations e.g. refactoring entire sub-systems over a week or more tends to yeild significant benefits.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/10/07/optimisation-effort-vs-performance-gain/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

