<?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[Was ist schneller?]]></title><description><![CDATA[<p>Ich hab 'ne Frage zur Codeoptimierung: Was ist schneller? Auch wenn nur minimal</p>
<ol>
<li>x &lt;&lt; y oder x * (2*y)</li>
<li>x &gt;&gt; y oder x / (2*y)</li>
<li>x / 2 oder x * .5</li>
<li>x /= y oder x= x/y</li>
<li>a=1/b; x=a*x; y=a*y; oder x= x/b; y= y/b</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/topic/196911/was-ist-schneller</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 18:59:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/196911.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Nov 2007 14:21:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 14:21:52 GMT]]></title><description><![CDATA[<p>Ich hab 'ne Frage zur Codeoptimierung: Was ist schneller? Auch wenn nur minimal</p>
<ol>
<li>x &lt;&lt; y oder x * (2*y)</li>
<li>x &gt;&gt; y oder x / (2*y)</li>
<li>x / 2 oder x * .5</li>
<li>x /= y oder x= x/y</li>
<li>a=1/b; x=a*x; y=a*y; oder x= x/b; y= y/b</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/1397491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397491</guid><dc:creator><![CDATA[Blaze]]></dc:creator><pubDate>Sun, 04 Nov 2007 14:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 14:28:54 GMT]]></title><description><![CDATA[<p>alles uninteressant, da der compiler das alles wegoptimiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397497</guid><dc:creator><![CDATA[kenner des compiler]]></dc:creator><pubDate>Sun, 04 Nov 2007 14:28:54 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 14:32:47 GMT]]></title><description><![CDATA[<p>Multi schneller als Div<br />
BitShift schneller als Multi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397499</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sun, 04 Nov 2007 14:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 14:32:49 GMT]]></title><description><![CDATA[<p>Falsch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397500</guid><dc:creator><![CDATA[Kenner der Kenner]]></dc:creator><pubDate>Sun, 04 Nov 2007 14:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 21:57:59 GMT]]></title><description><![CDATA[<p>Grundsätzlich sollte man Multiplikation gegenüber Division bevorzugen. Verwende beim Rest das, was der Algorithmus auch aussagt. Der Compiler optimiert sowieso Multiplikation/Division zu Shifts, sofern das möglich ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397789</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Sun, 04 Nov 2007 21:57:59 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Sun, 04 Nov 2007 22:09:07 GMT]]></title><description><![CDATA[<p>zu 99% &quot;optimierst&quot; du hier sowieso an der falschen stelle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397795</guid><dc:creator><![CDATA[und]]></dc:creator><pubDate>Sun, 04 Nov 2007 22:09:07 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Mon, 05 Nov 2007 03:06:15 GMT]]></title><description><![CDATA[<p>Den 2^y Fall optimiert der Compiler nur wenn y eine compile-time Konstante ist. Wenn y keine compile-time Konstante ist auf jeden Fall x &lt;&lt; y schreiben.</p>
<p>Das Beispiel (5) optimieren viele Compiler nicht selbst zu Multiplikationen, da das Ergebnis leicht anders ist als bei direkter Division (und damit nichtmehr mit dem zusammenstimmt was man laut IEEE Standard erwarten dürfte).</p>
<p>(4) ist vollkommen egal solange es sich um eingebaute Typen handelt, und (3) wird wohl von vielen Compilern zu einer Multiplikation verwandelt werden, solange der Kehrwert der Konstante exakt als float/double abbildbar ist.</p>
<p>Wenn du wissen willst was allgemein schnell/langsam ist, hier mal von schnell nach langsam sortiert:</p>
<ol>
<li>Addition, Subtraktion, Shiften, AND/OR/XOR</li>
<li>Multiplikation</li>
<li>Division, Modulo</li>
<li>sin, cos, tan, exp, log, ...</li>
</ol>
<p>If Abfragen (bzw. allgemein bedingte Sprünge) können auch einiges an Zeit kosten, lässt sich aber nicht einfach abschätzen wieviel. Es KANN z.B. Sinn machen eine Multiplikation mehr zu haben wenn man dafür ein if spart, es KANN aber genausogut sein dass es mit dem if und einer Multiplikation weniger schneller ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397825</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 05 Nov 2007 03:06:15 GMT</pubDate></item><item><title><![CDATA[Reply to Was ist schneller? on Mon, 05 Nov 2007 08:38:45 GMT]]></title><description><![CDATA[<p>Blaze schrieb:</p>
<blockquote>
<p>Ich hab 'ne Frage zur Codeoptimierung: Was ist schneller? Auch wenn nur minimal</p>
<ol>
<li>x &lt;&lt; y oder x * (2*y)</li>
<li>x &gt;&gt; y oder x / (2*y)</li>
</ol>
</blockquote>
<p>Die beiden Codes sind nicht einmal äquivalent. Ansonsten hängt es wohl davon ab, mit was für Werten du arbeitest (bei double ist die Shift-Variante nicht möglich, bei konstantem y wird der Compiler das vermutlich rausoptimieren)</p>
<blockquote>
<ol start="3">
<li>x / 2 oder x * .5</li>
</ol>
</blockquote>
<p>Das hängt davon ab, von welchen Typen wir reden - bei Gleitkommazahlen ist die zweite Variante eventuell besser, bei int's die erste.</p>
<blockquote>
<ol start="4">
<li>x /= y oder x= x/y</li>
</ol>
</blockquote>
<p>Macht für Build-in Typen keinen wesentlichen Unterschied - bei selbsterzeugten Typen (mit überladenen Operatoren) sollte die erste Variante schneller sein.</p>
<blockquote>
<ol start="5">
<li>a=1/b; x=a*x; y=a*y; oder x= x/b; y= y/b</li>
</ol>
</blockquote>
<p>Hier gilt das selbe wie bei 3 (btw, mit int-Werten liefert die erste Variante falsche Ergebnisse)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1397881</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1397881</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Nov 2007 08:38:45 GMT</pubDate></item></channel></rss>