<?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>Code execution time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33007/code-execution-time</link><description>Hi, 
 I&amp;#39;am using sdk14.2 with S140 V5.0.2-alpha. 
 I want to measure a time execution of a snippet code (ciphering function), and i want to display the time value with NRF_LOG_INFO, or SEGGER_rtt. 
 i know that there are other methods like toggling GPIO</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 Feb 2020 08:11:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33007/code-execution-time" /><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/233887?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 08:11:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dda2adb9-f746-47b2-931c-c1e5ddc2a961</guid><dc:creator>Sai Kiran</dc:creator><description>&lt;p&gt;I am having the same issue. sdk_config.h file is configured properly. I do not understand how to start a dummy timer. Can you show some code regarding this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126860?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 13:08:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc31b2ce-92fb-49cb-afe4-6622c5b3b531</guid><dc:creator>TAR CHAL</dc:creator><description>&lt;p&gt;thanks, after timer start i have a value of 8 ticks for begining and 12 ticks for the end, 4 ticks to realize the cifer and 4ticks = 91us, i think that it&amp;#39;s pretty good for a cortex m4f,&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126851?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 12:51:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b497371b-b865-4589-8fcf-99d6976e649a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Did you also create and start a &amp;quot;dummy timer&amp;quot;, to make sure RTC is running? RTC will not start until a timer is created, even it you have set the config. The config is also needed to make sure the RTC is not stopped if the last timer is stopped, but by leaving the &amp;quot;dummy timer&amp;quot; running, you make sure this never happens anyway.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126847?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 12:42:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c78a0b4c-fa61-463c-9a84-5cdc19cbc329</guid><dc:creator>TAR CHAL</dc:creator><description>&lt;p&gt;yes you right, the RTC in the sdk config was disabled, but when i enabled it and rebuiled my app, still have the same problem!!!!!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/4336.log.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/4336.log.PNG"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/3617.rtc.PNG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126808?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 10:50:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d9fc0ad-efc7-424b-9d13-eed514265ecf</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You need the RTC to be running in order to get values. Please make sure you set the SDK config macro described in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/16863/how-can-i-know-the-run-time-plz-help-me/64573#64573"&gt;this post&lt;/a&gt;, and start a &amp;quot;dummy timer&amp;quot; to make sure the RTC is started.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126791?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 09:45:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c480d2c-3e82-41b7-8131-b2ab8f796f6f</guid><dc:creator>TAR CHAL</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/joh2"&gt;J&amp;oslash;rgen&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Thanks for reply, i had exactly the same idea, i put app_timer_cnt_get() before and after my cifer funtion but in result i have &lt;strong&gt;&amp;quot;0&amp;quot;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;i don&amp;#39;t&amp;nbsp;know why i have this result but it&amp;#39;s seems like when i debug the code, the RTC don&amp;#39;t count !!,&lt;/p&gt;
&lt;p&gt;here a snippet code of my application&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*my cifer function */
static void skip_encrypt(void){
	uint32_t begin = 0;
	uint32_t end = 0;

	/*variables of the cifer function*/
    static BYTE Key[_SKIP32_KEY_LEN] = {1,5,16,18,50,47,54,42,32,47};
    DWORD encrypt = 15;
    DWORD invalue = 45;

    /*where i want to calculate code time */
    begin = app_timer_cnt_get();
	skip32_initWithKey(Key);
    skip32_encrypt(&amp;amp;encrypt,invalue);
    end = app_timer_cnt_get();
    NRF_LOG_INFO(&amp;quot;result time in ticks = %d \n&amp;quot;, app_timer_cnt_diff_compute(end,begin));
   }
/**
 * @brief Function for application main entry.
 */
int main(void)
{
	log_init();
	timers_init();
	skip_encrypt();
	ble_stack_init();
	.
	.
	.
	.
	.
	.
	
	advertising_init();
	advertising_start();



	//application_timers_start();
	// Enter main loop.
	for (;;) {
		if (NRF_LOG_PROCESS() == false) {
			power_manage();
		}
	}

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you have any idea why i have 0 in output ?&lt;/p&gt;
&lt;p&gt;just a remarque : when i put the first app_timer_cnt_get() just after timer_init(), and the second after advertising_start(), i have an output of &amp;quot;&lt;strong&gt;3&lt;/strong&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Code execution time</title><link>https://devzone.nordicsemi.com/thread/126780?ContentTypeID=1</link><pubDate>Wed, 04 Apr 2018 09:26:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b407f268-8b2c-417c-9b17-3fbc6a169f49</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can setup the application timer library, and use the functions&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/group__app__timer.html#gae36265bac1480fbb1522f63f70ac369f"&gt;app_timer_cnt_get&lt;/a&gt;&amp;nbsp;before and after your function call, and&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/group__app__timer.html#ga19d88a7d3da7d03f8a2c956a2ac5ccf3"&gt;app_timer_cnt_diff_compute&lt;/a&gt;&amp;nbsp;at the end to compute the time spent by the function. Note that this will give you the value in ticks, and you will have to calculate the actual time if you need this. Also note that if any interrupts happens within the function, the time spent handling the interrupts will also be counted.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>