<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic The only think i recognised in Software Tuning, Performance Optimization &amp; Platform Monitoring</title>
    <link>https://community.intel.com/t5/Software-Tuning-Performance/Analyzing-execution-time/m-p/1147358#M6798</link>
    <description>&lt;P&gt;The only&amp;nbsp;think i recognised when i looked at tour code it is: seond one is faster&lt;/P&gt;&lt;P&gt;but i have no idea what to answer about your question&lt;/P&gt;</description>
    <pubDate>Wed, 07 Nov 2018 14:22:40 GMT</pubDate>
    <dc:creator>mayer__max</dc:creator>
    <dc:date>2018-11-07T14:22:40Z</dc:date>
    <item>
      <title>Analyzing execution time</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/Analyzing-execution-time/m-p/1147357#M6797</link>
      <description>&lt;P&gt;
	&lt;STYLE type="text/css"&gt;p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; min-height: 14.0px}
	&lt;/STYLE&gt;
&lt;/P&gt;

&lt;P class="p1"&gt;Hello. I am working on analyzing execution time.&lt;/P&gt;

&lt;P class="p1"&gt;I have two similar codes below.&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P class="p1"&gt;&lt;B&gt;1st code:&lt;/B&gt;&lt;/P&gt;

&lt;P class="p1"&gt;int size = 256*1024*1024;&lt;/P&gt;

&lt;P class="p1"&gt;int stride = 256;&lt;/P&gt;

&lt;P class="p1"&gt;void *array = malloc(size);&lt;/P&gt;

&lt;P class="p1"&gt;for (unsigned long off = 0; off &amp;lt; size; off += stride) {&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; *(unsigned int *)(array+off) = off+stride;&lt;/P&gt;

&lt;P class="p1"&gt;}&lt;/P&gt;

&lt;P class="p1"&gt;*(unsigned int*)(array+off) = 0;&lt;/P&gt;

&lt;P class="p1"&gt;int i=10000000;&lt;/P&gt;

&lt;P class="p1"&gt;struct timeval start, end;&lt;/P&gt;

&lt;P class="p1"&gt;gettimeofday(&amp;amp;start, NULL);&lt;/P&gt;

&lt;P class="p1"&gt;while (i&amp;gt;=1) {&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; offset = *(unsigned int*)(array+off);&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; i--;&lt;/P&gt;

&lt;P class="p1"&gt;}&lt;/P&gt;

&lt;P class="p1"&gt;gettimeofday(&amp;amp;end, NULL);&lt;/P&gt;

&lt;P class="p1"&gt;*(volatile unsigned int*)(array+offset);&lt;/P&gt;

&lt;P class="p1"&gt;printf("%.2f\n", (end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec));&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P class="p1"&gt;&lt;B&gt;2nd code:&lt;/B&gt;&lt;/P&gt;

&lt;P class="p1"&gt;int size = 256*1024*1024;&lt;/P&gt;

&lt;P class="p1"&gt;int stride = 256;&lt;/P&gt;

&lt;P class="p1"&gt;void *array = malloc(size);&lt;/P&gt;

&lt;P class="p1"&gt;for (unsigned long off = 0; off &amp;lt; size; off += stride) {&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; *(unsigned int *)(array+off) = off+stride;&lt;/P&gt;

&lt;P class="p1"&gt;}&lt;/P&gt;

&lt;P class="p1"&gt;*(unsigned int*)(array+off) = 0;&lt;/P&gt;

&lt;P class="p1"&gt;int i=10000000;&lt;/P&gt;

&lt;P class="p1"&gt;struct timeval start, end;&lt;/P&gt;

&lt;P class="p1"&gt;gettimeofday(&amp;amp;start, NULL);&lt;/P&gt;

&lt;P class="p1"&gt;#define ONE&amp;nbsp;offset = *(unsigned int*)(array+off);&lt;/P&gt;

&lt;P class="p1"&gt;#define FIVE ONE ONE ONE ONE ONE&lt;/P&gt;

&lt;P class="p1"&gt;#define TEN FIVE FIVE&lt;/P&gt;

&lt;P class="p1"&gt;#define FIFTY TEN TEN TEN TEN TEN&lt;/P&gt;

&lt;P class="p1"&gt;#define HUNDRED FIFTY FIFTY&lt;/P&gt;

&lt;P class="p1"&gt;while (i&amp;gt;=1000) {&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; HUNDRED&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp; &amp;nbsp; i-=1000;&lt;/P&gt;

&lt;P class="p1"&gt;}&lt;/P&gt;

&lt;P class="p1"&gt;gettimeofday(&amp;amp;end, NULL);&lt;/P&gt;

&lt;P class="p1"&gt;*(volatile unsigned int*)(array+offset);&lt;/P&gt;

&lt;P class="p1"&gt;printf("%.2f\n", (end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec));&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P class="p1"&gt;&lt;BR /&gt;
	&lt;STRONG&gt;Questions&lt;/STRONG&gt;&lt;/P&gt;

&lt;P class="p1"&gt;1) The only difference between two codes is "while loop."&lt;/P&gt;

&lt;P class="p1"&gt;They both measure the elapsed time for while loop.&lt;/P&gt;

&lt;P class="p1"&gt;When I executed two codes with my computer (with disabled hardware prefetch), the first code makes a result of 779,851,000 ns and the second code makes a result of 1,624,344,000 ns (2.1 times larger)&lt;/P&gt;

&lt;P class="p1"&gt;I thought this difference comes from L1-i cache misses, so I measured L1-i cache misses with perf.&lt;/P&gt;

&lt;P class="p1"&gt;However, the L1-i cache miss of the first code is 34,541 and the L1-i cache miss of the second code is 43,078 (1.2 times larger),&lt;/P&gt;

&lt;P class="p1"&gt;This result cannot completely explain the difference in elapsed times for while loop.&lt;/P&gt;

&lt;P class="p1"&gt;What makes the big difference between elapsed times of two codes? Is there anything that I miss?&lt;/P&gt;

&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;

&lt;P class="p1"&gt;2) When I used Top-down analysis of general exploration of VTune with the first code, I got total elapsed time of 1.125 s and DRAM bound of 51.3 %. The measured elapsed time for while loop (=result of this program) was 926,295,000 ns.&lt;/P&gt;

&lt;P class="p1"&gt;I expected the DRAM stall time (1.125*51.3/100 = 0.577 s) would be equal or larger than the result of the program (0.926295 s) since all instructions in the while loop make LLC miss.&lt;/P&gt;

&lt;P class="p1"&gt;However, measured elapsed time is about 1.6 times larger than the DRAM stall time.&lt;/P&gt;

&lt;P class="p1"&gt;Why are the two values different?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 17:15:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/Analyzing-execution-time/m-p/1147357#M6797</guid>
      <dc:creator>Yukyoung_L_</dc:creator>
      <dc:date>2018-10-23T17:15:20Z</dc:date>
    </item>
    <item>
      <title>The only think i recognised</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/Analyzing-execution-time/m-p/1147358#M6798</link>
      <description>&lt;P&gt;The only&amp;nbsp;think i recognised when i looked at tour code it is: seond one is faster&lt;/P&gt;&lt;P&gt;but i have no idea what to answer about your question&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 14:22:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/Analyzing-execution-time/m-p/1147358#M6798</guid>
      <dc:creator>mayer__max</dc:creator>
      <dc:date>2018-11-07T14:22:40Z</dc:date>
    </item>
  </channel>
</rss>

