<?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[langsame funktionen in c++]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>könnt ihr mir mal sagen, welche Funktionsaufrufe in C++<br />
langsam ablaufen, die man zb in einem Spiel vermeiden bzw<br />
verringer sollte?</p>
<p>Was ich weiß, ist zb dass sqrt langsam ist, aber wie siehts mit sin, cos, tan aus?</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165285/langsame-funktionen-in-c</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 17:20:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165285.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Nov 2006 10:59:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 10:59:45 GMT]]></title><description><![CDATA[<p>Hey Leute,</p>
<p>könnt ihr mir mal sagen, welche Funktionsaufrufe in C++<br />
langsam ablaufen, die man zb in einem Spiel vermeiden bzw<br />
verringer sollte?</p>
<p>Was ich weiß, ist zb dass sqrt langsam ist, aber wie siehts mit sin, cos, tan aus?</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176531</guid><dc:creator><![CDATA[_carnage]]></dc:creator><pubDate>Sat, 18 Nov 2006 10:59:45 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 11:09:43 GMT]]></title><description><![CDATA[<p>die sind wahrscheinlich auch langsam, ich hab mal gelernt, sdass man sich bei langsamen Funktionen die Werte, die man Braucht vorberechnen soll, und sie dann in einem array speichern soll, dann muss man nurnoch auf das Ergebnis zugreifen, und kann so einiges an Berechnungszeit Sparen, weil die Ergebnisse nich immer neu Ausgerechnet werden müssen. Die lässt sich ganz einfach durch eine redefinition der Funktion lösen, die dann statt double nur integer annimmt, und intern ein Statisches array hat, in dem die Ergebnisse drinstehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176538</guid><dc:creator><![CDATA[Krux]]></dc:creator><pubDate>Sat, 18 Nov 2006 11:09:43 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 11:22:47 GMT]]></title><description><![CDATA[<p>sin cos und tan sind 0(1)</p>
<p>sqrt kann man vereinfacht reimplementieren, um die anzahl der iterationen zu verringern</p>
<p>wenn ich mich richtig erinnere gibts auf neueren cpu's sogar einen asm befehl der das ganze in O(1) erledigt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176540</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Sat, 18 Nov 2006 11:22:47 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 14:22:18 GMT]]></title><description><![CDATA[<p>O(1) bedeutet nur, dass sie eine konstante Laufzeit haben, also nicht bei wachsender Problemgröße ansteigen, aber es sagt nicht über die Tatsächliche Laufzeit aus, Aber in der Funktion ist auch garkeine Problemgröße festgelegt, was dazu führ, dass es eine Konstante Laufzeit haben muss. Die Laufzeit kann 1000 mal häher sein, als der Zugriff auf ein Datenelement eines Arrays, und trotz dem ist die Laufzeit O(1).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176612</guid><dc:creator><![CDATA[Krux]]></dc:creator><pubDate>Sat, 18 Nov 2006 14:22:18 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 14:26:50 GMT]]></title><description><![CDATA[<p>vielleicht meint r0nny das es gleich schnell ist egal wieviele ziffern die zahl hat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176615</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176615</guid><dc:creator><![CDATA[^^]]></dc:creator><pubDate>Sat, 18 Nov 2006 14:26:50 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 14:31:07 GMT]]></title><description><![CDATA[<p>sin cos und tan sind einfach multiplikationen</p>
<p>sqrt ist eine iteration/rekursion einer gewissen tiefe (meistens ist 20 - 40 mehr als ausreichend</p>
<p>einige cpu's können sqrt in hardware und ohne langwierige iteration -&gt; nur ein paar takte anstatt ein paar hundert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176617</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176617</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Sat, 18 Nov 2006 14:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 14:31:16 GMT]]></title><description><![CDATA[<p>Krux schrieb:</p>
<blockquote>
<p>O(1) bedeutet nur, dass sie eine konstante Laufzeit haben, also nicht bei wachsender Problemgröße ansteigen, aber es sagt nicht über die Tatsächliche Laufzeit aus, Aber in der Funktion ist auch garkeine Problemgröße festgelegt, was dazu führ, dass es eine Konstante Laufzeit haben muss.</p>
</blockquote>
<p>Ach, und Faktorisiere(int zahl) hat demnach auch konstante Laufzeit, weil ja keine Problemgröße spezifiziert ist? Zeig mal Deine Implementierung davon. <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/1176618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176618</guid><dc:creator><![CDATA[Jester]]></dc:creator><pubDate>Sat, 18 Nov 2006 14:31:16 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 18:24:40 GMT]]></title><description><![CDATA[<p>Folgender Code soll die Sinus-Funktion beschleunigen, ich hab allerdings nicht ausprobiert ob es wirklich was bringt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;iomanip&gt;

namespace fast
{
    const int arrsize = 1024;
    const double maxRadian = 2 * M_PI;

    double arr[arrsize];

    void InitSin()
    {
        for (int i = 0; i &lt; arrsize; ++i)
        {
            arr[i] = sin(maxRadian * i / arrsize);
        }
    }

    inline double sin(double r)
    {
        if(r &lt; 0)
        {
            r = -r + maxRadian / 2;
        }
        while(r &gt; maxRadian)
        {
            r -= maxRadian;
        }
        return arr[static_cast&lt;size_t&gt;(r * arrsize / maxRadian)];
    }
}
int main()
{
    fast::InitSin();
    std::cout &lt;&lt; std::setprecision(6) &lt;&lt; std::fixed;
    for (double i = -1; i &lt; 3; i += 0.4)
    {
        std::cout &lt;&lt; fast::sin(i) &lt;&lt; std::endl &lt;&lt; sin(i) &lt;&lt; std::endl &lt;&lt; std::endl;
    }
}
</code></pre>
<p>mfg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176767</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Sat, 18 Nov 2006 18:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 19:12:46 GMT]]></title><description><![CDATA[<p>die &quot;fast&quot; ist saulahm für große werte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176787</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Sat, 18 Nov 2006 19:12:46 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 20:22:57 GMT]]></title><description><![CDATA[<p>r0nny schrieb:</p>
<blockquote>
<p>die &quot;fast&quot; ist saulahm für große werte</p>
</blockquote>
<p>ja das stimmt. Mir ist nicht eingefallen wie man das sonst lösen sollte. Wie würde man dass denn machen?</p>
<p>mfg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176839</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Sat, 18 Nov 2006 20:22:57 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sat, 18 Nov 2006 21:56:10 GMT]]></title><description><![CDATA[<p>division mit anschliesender multiplikation des flieskommaanteils</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176872</guid><dc:creator><![CDATA[ronny]]></dc:creator><pubDate>Sat, 18 Nov 2006 21:56:10 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sun, 19 Nov 2006 00:24:46 GMT]]></title><description><![CDATA[<p>Jo, durch 2 Pi, dann alles vor dem Komma weg, und mal Tabellengrösse (die idealerweise gleich ne 2er Potenz ist), dann ab nach Integer und als Index in die Tabelle verwenden.<br />
Geht halt wirklich nur wenn man keine sehr gute Genauigkeit braucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176914</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 19 Nov 2006 00:24:46 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sun, 19 Nov 2006 00:25:47 GMT]]></title><description><![CDATA[<p>r0nny schrieb:</p>
<blockquote>
<p>sin cos und tan sind einfach multiplikationen</p>
</blockquote>
<p>oh, auf die begründung dieser aussage bin ich mal echt gespannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176916</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Sun, 19 Nov 2006 00:25:47 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Sun, 19 Nov 2006 00:39:53 GMT]]></title><description><![CDATA[<p>r0nny schrieb:</p>
<blockquote>
<p>sqrt ist eine iteration/rekursion einer gewissen tiefe (meistens ist 20 - 40 mehr als ausreichend</p>
</blockquote>
<p>auf dem 64-er nahen wir 3 newton-iterationen, wenn ich mich recht erinnere. als startwert den float mit alter mantisse und halbem exponent.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176922</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 19 Nov 2006 00:39:53 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Mon, 20 Nov 2006 15:44:54 GMT]]></title><description><![CDATA[<p>sqrt kann man manchmal auch weglassen. Aus</p>
<pre><code class="language-cpp">if (x &lt; sqrt(y))
</code></pre>
<p>wird dann zB dies</p>
<pre><code class="language-cpp">if (x*x &lt; y)
</code></pre>
<p>Was logisch gleich ist, jedoch deutlich flotter berechnet werden kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177901</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Mon, 20 Nov 2006 15:44:54 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Mon, 20 Nov 2006 16:01:46 GMT]]></title><description><![CDATA[<p>Aißerdem braucht man (ich) fast immer nur float bei trigonometrischen Berechnunen, double dauert ja noch mal länger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177913</guid><dc:creator><![CDATA[Carmack]]></dc:creator><pubDate>Mon, 20 Nov 2006 16:01:46 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Mon, 20 Nov 2006 16:07:15 GMT]]></title><description><![CDATA[<blockquote>
<p>sqrt kann man manchmal auch weglassen. Aus</p>
<pre><code class="language-cpp">if (x &lt; sqrt(y))
</code></pre>
<p>wird dann zB dies</p>
<pre><code class="language-cpp">if (x*x &lt; y)
</code></pre>
<p>Was logisch gleich ist, jedoch deutlich flotter berechnet werden kann.</p>
</blockquote>
<p>Und was machst du wenn x eine negative Zahl ist?</p>
<p>Das mit sin cos tan und der multiplikation würd mich auch mal interessieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177916</guid><dc:creator><![CDATA[Mario Sandler]]></dc:creator><pubDate>Mon, 20 Nov 2006 16:07:15 GMT</pubDate></item><item><title><![CDATA[Reply to langsame funktionen in c++ on Mon, 20 Nov 2006 17:34:43 GMT]]></title><description><![CDATA[<p><a href="http://Storm.Xapek.de" rel="nofollow">Storm.Xapek.de</a> schrieb:</p>
<blockquote>
<p>Und was machst du wenn x eine negative Zahl ist?</p>
</blockquote>
<p>Uninteressant, wenn es um Beträge geht (was bei sqrt meistens der Fall ist). Ich schrieb ja auch nicht, dass es immer möglich ist. Man muss halt von Fall zu Fall abwägen, ob die Vereinfachung sinnvoll ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177967</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Mon, 20 Nov 2006 17:34:43 GMT</pubDate></item></channel></rss>