<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How can I turn on time-optimisation of one small section of code in a &amp;quot;debug&amp;quot; build.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54267/how-can-i-turn-on-time-optimisation-of-one-small-section-of-code-in-a-debug-build</link><description>I have a time-critical code section in a call-back routine which is too slow to work when run as a &amp;quot;debug&amp;quot; build, but works fine when run as a &amp;quot;release&amp;quot; build. 
 This is a problem because I can&amp;#39;t set break points etc in a release build to help me debug</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Nov 2019 13:43:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54267/how-can-i-turn-on-time-optimisation-of-one-small-section-of-code-in-a-debug-build" /><item><title>RE: How can I turn on time-optimisation of one small section of code in a "debug" build.</title><link>https://devzone.nordicsemi.com/thread/219689?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 13:43:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8247ff2b-8b8c-419f-add5-59b10083065a</guid><dc:creator>Nicholas Lee</dc:creator><description>&lt;p&gt;Ah, of course!&lt;br /&gt;&lt;br /&gt;For anyone else reading this, here is some useful explanation of the different optimisation levels and what they do (assuming SEGGER and the GCC compiler).&lt;br /&gt;&lt;br /&gt;&lt;span class="inline_editor_value"&gt;&lt;span class="ui_qtext_rendered_qtext"&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;gcc&lt;/span&gt;&lt;/code&gt;&lt;/code&gt; offers four compilation levels, plus a size optimisation level.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O0&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. No optimization. This is the default. There is a clear relationship between each line of code and each resulting machine instruction. The compiler is actually slower at this level, as dead-code elimination and other unperformed optimizations minimize the amount of work the compiler needs to do. Moreover, some warnings are not available with optimization disabled as the compiler cannot detect certain issues without using its optimizer. The only use case for this level is debugging, but I try to debug in my standard level if at all possible.&lt;/li&gt;
&lt;li&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O1&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. Enables basic optimizations. There generally isn&amp;#39;t a reason to use this level over the next.&lt;/li&gt;
&lt;li&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O2&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. Enables even more optimizations. This mode turns on nearly all optimizations that do not incur significant space-time tradeoffs. This is the default for many software projects, including the Linux kernel and all GNU projects. Because it is the default for so many (important) projects, it is the most tested option. This level is my recommendation.&lt;/li&gt;
&lt;li&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O3&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. Enables yet more optimizations. This includes optimizations that incur a space-time tradeoff in favor of time, such as loop unrolling and automatic function inlining. Your binary will almost certainly be larger. Your program &lt;i&gt;may&lt;/i&gt; be faster.&lt;/li&gt;
&lt;li&gt;&lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="typ"&gt;Os&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. Optimize for size. This mode is similar to &lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O2&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;, except a handful of optimizations are disabled and a handful of new ones are enabled. Your binary will almost certainly be smaller than with &lt;code class="prettyprint inline prettyprinted"&gt;&lt;code class="language-console"&gt;&lt;span class="pln"&gt;O2&lt;/span&gt;&lt;/code&gt;&lt;/code&gt;. It is also likely to be slower, although it may be faster, due to improved cache utilization.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Right clicking on the file you want to modify in the project tree and selecting &amp;quot;options&amp;quot;.&lt;br /&gt;Select the build type you want to modify the settings for, in the top left of the IDE. (release or debug).&lt;br /&gt;Then select &amp;quot;code&amp;quot;, then &amp;quot;code-generation&amp;quot;, and then &amp;quot;optimization level&amp;quot;, and you will get the following dialogue screen.&lt;br /&gt;Then select the desired optimization level override. &lt;br /&gt;Typically you will want to use &amp;quot;None&amp;quot; for debug, or &amp;quot;Level 1&amp;quot; for release.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/486x436/__key/communityserver-discussions-components-files/4/Optimisation.jpg" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I turn on time-optimisation of one small section of code in a "debug" build.</title><link>https://devzone.nordicsemi.com/thread/219576?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2019 05:17:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:880dbb73-f0fe-44e6-aa22-bac5930e624c</guid><dc:creator>WestCoastDaz</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/nicholaslee"&gt;Nicholas Lee&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You should be able to turn on optimizations for just that file.&amp;nbsp; If you right click on the file name on the Project Explorer view you can override the inherited Optimization Level under the Code Generation menu for this specific file.&lt;/p&gt;
&lt;p&gt;I am assuming of course that the code you are&amp;nbsp;trying to make faster in debug doesn&amp;#39;t have an print statements or extra work that is not performed in the release build.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Darren&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>