<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gibt es hier Performance Unterschiede?]]></title><description><![CDATA[<p>Da ich kein Fan von aneinandergeketteten Abfragen bin schreibe ich lieber</p>
<p><strong>A</strong></p>
<pre><code class="language-cpp">if (board.black_queens &gt;= 1) {
  if (black_king_attacker_n &gt;= 2) {
    if (material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O) {
      if (black_king_adjacent_zone_attack_n) {
        // ...
</code></pre>
<p>anstatt</p>
<p><strong>B</strong></p>
<pre><code class="language-cpp">if (board.black_queens &gt;= 1 &amp;&amp;
    black_king_attacker_n &gt;= 2 &amp;&amp;
    material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O &amp;&amp;
    black_king_adjacent_zone_attack_n &amp;&amp;
    // ...
</code></pre>
<p>Ist das <em>dasselbe</em> für den Compiler, oder gibt es Performance-Unterschiede? Ich kann das nur schwierig testen, da meine gesamten Sources wie in <strong>A</strong> angelegt sind.</p>
<p>Und was ist eurer Meinung nach <em>besser</em> ?</p>
<p>Danke schonmal für eure Statements <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252903/gibt-es-hier-performance-unterschiede</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:19:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252903.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Oct 2009 10:28:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 10:28:44 GMT]]></title><description><![CDATA[<p>Da ich kein Fan von aneinandergeketteten Abfragen bin schreibe ich lieber</p>
<p><strong>A</strong></p>
<pre><code class="language-cpp">if (board.black_queens &gt;= 1) {
  if (black_king_attacker_n &gt;= 2) {
    if (material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O) {
      if (black_king_adjacent_zone_attack_n) {
        // ...
</code></pre>
<p>anstatt</p>
<p><strong>B</strong></p>
<pre><code class="language-cpp">if (board.black_queens &gt;= 1 &amp;&amp;
    black_king_attacker_n &gt;= 2 &amp;&amp;
    material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O &amp;&amp;
    black_king_adjacent_zone_attack_n &amp;&amp;
    // ...
</code></pre>
<p>Ist das <em>dasselbe</em> für den Compiler, oder gibt es Performance-Unterschiede? Ich kann das nur schwierig testen, da meine gesamten Sources wie in <strong>A</strong> angelegt sind.</p>
<p>Und was ist eurer Meinung nach <em>besser</em> ?</p>
<p>Danke schonmal für eure Statements <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798426</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Mon, 26 Oct 2009 10:28:44 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 10:38:12 GMT]]></title><description><![CDATA[<p>Es ist nicht dasselbe für den compiler, moderne compiler machen aber daraus den selben code.</p>
<p>Solche verschachtelten Bedingungsblöcke sind Unsinn. Setze anstatt dessen einfach die boolschen Operatoren an eine konstante Tab-Stelle, damit die Bedingunsliste übersichtlicher aussieht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798435</guid><dc:creator><![CDATA[sqrt(-1)]]></dc:creator><pubDate>Mon, 26 Oct 2009 10:38:12 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 10:45:23 GMT]]></title><description><![CDATA[<p>Solche verschachtelten Bedingungsblöcke sind prima.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798440</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 26 Oct 2009 10:45:23 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 11:53:55 GMT]]></title><description><![CDATA[<p>Ich würde sagen B kann nicht schlechter sein als A. Beim &quot;&amp;&amp;&quot;, auch &quot;short circuit AND&quot; genannt, wird der zweite Operand nur auswertet, wenn der erste Operand <code>true</code> ist. Aber A könnte langsamer sein als B. Nicht vielleicht in Deinem Fall, aber wenn man zB Intervalle testet:</p>
<pre><code class="language-cpp">int foo(int x)
{
  if (1 &lt;= x &amp;&amp; x &lt;= 3) return 23;
  return 42;
}

int bar(int x)
{
  if (1 &lt;= x)
    if (x &lt;= 3) return 23;
  return 42;
}
</code></pre>
<p>Im ersten Fall könnte ein schlauer Compiler den Test 1&lt;=x&amp;&amp;x&lt;=3 zu etwas wie unsigned(i-1)&lt;=2 umbauen (eine Verzweigung gespart). Im zweiten Fall halte ich das nicht mehr so ganz für wahrscheinlich, dass ein Compiler diese Optimierung auch durchfuhren kann.</p>
<p>Wenn Du's genau wissen willst, kannst Du Dir ja mal den generierten Assemblercode anschauen.</p>
<p>Edit: Hier ist der Assembler code (g++ version 3.4.5 auf x86 mit -O3)</p>
<pre><code>00000000 &lt;__Z3fooi&gt;:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   8b 45 08                mov    0x8(%ebp),%eax
   6:   5d                      pop    %ebp
   7:   48                      dec    %eax
   8:   83 f8 03                cmp    $0x3,%eax
   b:   19 c0                   sbb    %eax,%eax
   d:   83 e0 ed                and    $0xffffffed,%eax
  10:   83 c0 2a                add    $0x2a,%eax
  13:   c3                      ret
  14:   8d b6 00 00 00 00       lea    0x0(%esi),%esi
  1a:   8d bf 00 00 00 00       lea    0x0(%edi),%edi

00000020 &lt;__Z3bari&gt;:
  20:   55                      push   %ebp
  21:   89 e5                   mov    %esp,%ebp
  23:   8b 55 08                mov    0x8(%ebp),%edx
  26:   85 d2                   test   %edx,%edx
  28:   7e 0a                   jle    34 &lt;__Z3bari+0x14&gt;
  2a:   83 fa 03                cmp    $0x3,%edx
  2d:   b8 17 00 00 00          mov    $0x17,%eax
  32:   7e 05                   jle    39 &lt;__Z3bari+0x19&gt;
  34:   b8 2a 00 00 00          mov    $0x2a,%eax
  39:   5d                      pop    %ebp
  3a:   c3                      ret
  3b:   90                      nop
</code></pre>
<p>Das erste sieht mir irgendwie effizienter aus, da keine bedingten Sprünge.</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798441</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Mon, 26 Oct 2009 11:53:55 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 10:53:22 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Solche verschachtelten Bedingungsblöcke sind prima.</p>
</blockquote>
<p>Finde ich nicht:</p>
<pre><code class="language-cpp">if (board.black_queens &gt;= 1) {
  if (black_king_attacker_n &gt;= 2) {
    if (material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O) {
      if (black_king_adjacent_zone_attack_n) {
        ... Anweisungen
      }
    }
  }
}
</code></pre>
<pre><code class="language-cpp">if( board.black_queens &gt;= 1                                   &amp;&amp;
    black_king_attacker_n &gt;= 2                                &amp;&amp;
    material_item-&gt;black_non_pawn_material &gt;= VALUE_QUEEN_O   &amp;&amp;
    black_king_adjacent_zone_attack_n )
{
   ... Anweisungen
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1798446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798446</guid><dc:creator><![CDATA[sqrt(-1)]]></dc:creator><pubDate>Mon, 26 Oct 2009 10:53:22 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 11:20:20 GMT]]></title><description><![CDATA[<p>Ja, ich habs wiedermal komplett verpeilt. Wenn der Code komplizierter wird, ist auf jeden Fall Deine Version viel lesbarer, weil man den Ausdruck nicht inhaltlich zerlegen muß, sondern das einfach grafisch machen kann. Durch die Eingerückten &amp;&amp;-Zeichen ist sofort die totale Übersicht da.</p>
<pre><code class="language-cpp">bool datumIstGueltig(int tag,int monat,int jahr)
{
   if( monat&gt;0                          &amp;&amp;
       monat&lt;13                         &amp;&amp;
       tag&gt;0                            &amp;&amp;
       tag&lt;32                           &amp;&amp;
       (tag&lt;31                      ¦¦
       (monat&gt;7!=monat%2==1))           &amp;&amp;
       (monat!=2                    ¦¦
       (tag&lt;30                          &amp;&amp;
       (((jahr%4==0                     &amp;&amp;
       jahr%100!=0)                 ¦¦
       jahr%400==0)                 ¦¦
       tag&lt;29)))) 
       return true; 
   else 
      return false;
}
</code></pre>
<p>edit: Übersicht drastisch weiter verbessert, indem || auch einen Platz bekommen hat. Evtl sollte man für Vergleichsoperatoren auch einen Platz einräumen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798463</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 26 Oct 2009 11:20:20 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 13:35:24 GMT]]></title><description><![CDATA[<p>(A) ist auch angenehmer zu debuggen.<br />
ich verwende trotzdem meist (B).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798551</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 26 Oct 2009 13:35:24 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 19:37:23 GMT]]></title><description><![CDATA[<p>Ich finde B auch besser, weil es imo mehr das aussagt, was du sagen willst. Du willst, dass etwas UND etwas UND etwas nochmal anderes gleichezeitig wahr sind. Klar versteht man es mit if's auch, aber mit den Verknüpfungen finde ich es intuitiver.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798779</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 26 Oct 2009 19:37:23 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 20:42:32 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Ich finde B auch besser, weil es imo mehr das aussagt, was du sagen willst. Du willst, dass etwas UND etwas UND etwas nochmal anderes gleichezeitig wahr sind. Klar versteht man es mit if's auch, aber mit den Verknüpfungen finde ich es intuitiver.</p>
</blockquote>
<p>wieso sagt ihr das alle so absolut?<br />
ich finds idR auch schöner, logische operatoren statt 100 ifs zu benutzen, aber volkards bsp find ich z.bsp. mehr als unleserlich - aber das würd ich eh anders schreiben:</p>
<pre><code class="language-cpp">bool datumIstGueltig(int tag,int monat,int jahr)
{                  /*0...32, 0...11, 0...INT_MAX*/
  if(tag &lt; 0)
    return false;

  switch(monat)
  {
    case 0: //jan
    case 2: //mrz
    case 4: //mai
    case 6: //jul
    case 7: //aug
    case 9: //oct
    case 11: //dez
      return tag &lt; 32;

    case 3: //apr
    case 5: //jun
    case 8: //sep
    case 10: //nov
      return tag &lt; 31;

    case 1: //feb
      if((jahr%4 == 0) &amp;&amp; (jahr%400 == 0))
        return tag &lt; 29;
      return &lt; 28;

    default:
      return false;
   }
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798797</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 26 Oct 2009 20:42:32 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es hier Performance Unterschiede? on Mon, 26 Oct 2009 20:54:52 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>wieso sagt ihr das alle so absolut?</p>
</blockquote>
<p>Was war bei meiner Aussage absolut? - Ich habe gesagt, dass ich es (dort, ok habe ich nicht explizit gesagt..) intuitiver finde. Klar gibt es Fälle, wo es anderst rum besser verständlich ist.</p>
<p>Und auf volkards Beispiel habe ich mich gar nicht bezogen. - Deine Lösung gefällt mir da auch besser. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1798803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1798803</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 26 Oct 2009 20:54:52 GMT</pubDate></item></channel></rss>