<?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[math.h zu langsam]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich möchte ein Programm schreiben das die Wurzel einer Zahle zieht!</p>
<p>Bei der Quadratwurzel funktioniert es schon.<br />
Aber bei anderen Wurzeln benötige ich eine Zahl x hoch y, aber mit der Funktion pow(double, double) - im Header math.h - geht das, aber zu langsam!</p>
<p>Also habe ich eine eigene Funktion geschrieben:</p>
<pre><code>double raise(double x, int y)
{
double e=x;
 for(int a=0; a!=y; ++a)
 x*=e;
 return x;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/214559/math-h-zu-langsam</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 15:50:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/214559.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 30 May 2008 18:36:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:44:35 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich möchte ein Programm schreiben das die Wurzel einer Zahle zieht!</p>
<p>Bei der Quadratwurzel funktioniert es schon.<br />
Aber bei anderen Wurzeln benötige ich eine Zahl x hoch y, aber mit der Funktion pow(double, double) - im Header math.h - geht das, aber zu langsam!</p>
<p>Also habe ich eine eigene Funktion geschrieben:</p>
<pre><code>double raise(double x, int y)
{
double e=x;
 for(int a=0; a!=y; ++a)
 x*=e;
 return x;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1519903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519903</guid><dc:creator><![CDATA[tuxer]]></dc:creator><pubDate>Fri, 30 May 2008 18:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:42:16 GMT]]></title><description><![CDATA[<p>Das Semikolon am Ende des Schleifenkopfes gehört da nicht hin.<br />
Wenn y 0 ist, bekommst du übrigens kein richtiges Ergebnis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519907</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Fri, 30 May 2008 18:42:16 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:45:30 GMT]]></title><description><![CDATA[<p>für y = -1 bekommst du was ganz lustiges. und warum ist pow bei dir so wichtig fürs Wurzelziehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519910</guid><dc:creator><![CDATA[und]]></dc:creator><pubDate>Fri, 30 May 2008 18:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:51:39 GMT]]></title><description><![CDATA[<p>ja das mit der 0 überprüfe ich schon im Programm aber ist sonst noch irgendwo ein Fehler?</p>
<p>Das mit dem Semikolon habe ich schon ausgebessert.</p>
<p>edit:<br />
@und<br />
Ich ziehe in etwa so die Wurzel:</p>
<pre><code>// ein= Zahl von der die Wurzel gezogen werden soll
// root= 0
// w= welche Wurzel es ist
while(pow(root, w)&lt;ein)
root+=0.00000001;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1519911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519911</guid><dc:creator><![CDATA[tuxer]]></dc:creator><pubDate>Fri, 30 May 2008 18:51:39 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:51:02 GMT]]></title><description><![CDATA[<p>Du solltest e mit 1.0 initialisieren... dann verhält sich die Funktion auch bei y=0 richtig.<br />
Bei e=x musst du die Schleife einmal weniger als jetzt durchlaufen lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519912</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Fri, 30 May 2008 18:51:02 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 18:55:15 GMT]]></title><description><![CDATA[<p>tuxer schrieb:</p>
<blockquote>
<p>edit:<br />
@und<br />
Ich ziehe in etwa so die Wurzel:</p>
<pre><code>// ein= Zahl von der die Wurzel gezogen werden soll
// root= 0
// w= welche Wurzel es ist
while(pow(root, w)&lt;ein)
root+=0.00000001;
</code></pre>
</blockquote>
<p>Na, dann wundert es mich nicht, dass dir das Wurzelziehen zu lange dauert <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="😉"
    /><br />
Probier es doch so: root=pow(ein,1.0/w);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519914</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Fri, 30 May 2008 18:55:15 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 19:01:36 GMT]]></title><description><![CDATA[<p>Nanyuki schrieb:</p>
<blockquote>
<p>Probier es doch so: root=pow(ein,1.0/w);</p>
</blockquote>
<p>dauert immer noch genauso lange <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519916</guid><dc:creator><![CDATA[tuxer]]></dc:creator><pubDate>Fri, 30 May 2008 19:01:36 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 19:19:28 GMT]]></title><description><![CDATA[<p>tuxer schrieb:</p>
<blockquote>
<p>Nanyuki schrieb:</p>
<blockquote>
<p>Probier es doch so: root=pow(ein,1.0/w);</p>
</blockquote>
<p>dauert immer noch genauso lange <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
</blockquote>
<p>weil dein Programm zu ineffizient ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519922</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 30 May 2008 19:19:28 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 19:20:28 GMT]]></title><description><![CDATA[<p>tuxer schrieb:</p>
<blockquote>
<p>dauert immer noch genauso lange <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
</blockquote>
<p>Hast du die while-Schleife noch? Die Anweisung sollte alleine stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519923</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Fri, 30 May 2008 19:20:28 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 19:58:54 GMT]]></title><description><![CDATA[<p><a href="http://de.wikipedia.org/wiki/Wurzel_(Mathematik)#Numerische_Berechnung" rel="nofollow">http://de.wikipedia.org/wiki/Wurzel_(Mathematik)#Numerische_Berechnung</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519935</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Fri, 30 May 2008 19:58:54 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Fri, 30 May 2008 20:09:11 GMT]]></title><description><![CDATA[<p>Aha <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Jetzt kappier ich die Formel erst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /><br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519941</guid><dc:creator><![CDATA[tuxer]]></dc:creator><pubDate>Fri, 30 May 2008 20:09:11 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 08:21:40 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">inline float FastWurzelExact(float r)
{
    if(r == 0.0f)
        return 0.0f;

    if(r &lt; 0.0f)
        r = -r;

    Value = r;
    halfValue = 0.5f*r;

    ptr = (unsigned long*)&amp;r;
    *ptr=(0xbe6f0000-*ptr)&gt;&gt;1;
    temp1Wurzel = r;

    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;
    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;

    return Value*temp1Wurzel; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1520039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520039</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 31 May 2008 08:21:40 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 08:38:18 GMT]]></title><description><![CDATA[<p>Dieser Code ist weder kompilierbar, noch liefert exakte Ergebnise (sondern Approximationen). Und funktioniert vorrangig, in dieser Form, für Quadratwurzeln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520047</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sat, 31 May 2008 08:38:18 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 11:56:37 GMT]]></title><description><![CDATA[<p>Ausserdem gibts einige Unschönheiten:</p>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">inline float FastWurzelExact(float r)  // inline ist sehrwahrscheinlich langsamer
{
    if(r == 0.0f)        // Wird selten der Fall sein, siehe Float-Vergleich
        return 0.0f;

    if(r &lt; 0.0f)         // Willst du bei Wurzeln aus negativen Zahlen 
        r = -r;          // wirklich ein Resultat ausgeben?

    ptr = (unsigned long*)&amp;r;  // C-Style-Cast
}
</code></pre>
</blockquote>
<p>Aber was ist denn so schlecht an <code>sqrt()</code> ? Das ist wahrscheinlich auch schneller und genauer als deine eigene Funktion (die den Namen FastWurzelExact eigentlich nicht verdient hat ;))...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520141</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 31 May 2008 11:56:37 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 15:14:10 GMT]]></title><description><![CDATA[<p>Die ist mit grosser Wahrscheinlichkeit langsamer.. <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>
<p>Allerdings gab es diese Diskussion hier bereits einmal..</p>
<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-p-is-1487117.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-p-is-1487117.html</a></p>
<p>Hier gibt es noch einen interessanten Artikel über &quot;Fast inverse square root&quot;.<br />
<a href="http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf" rel="nofollow">http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520236</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 31 May 2008 15:14:10 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 17:39:24 GMT]]></title><description><![CDATA[<p>naja das ist eine routine aus einem buch üebr 3d spiele programmierung<br />
und so eine ähnliche wird in quake 3 verwendet</p>
<p>ok sie ist nicht so exakt, aber sie ist im gegensatz zu math::sqrt verdammt schnell</p>
<p>hab mal en test gemacht<br />
1000000 wurzeln gezogen<br />
math::sqrt hat 30 sek gebraucht<br />
meine funktion hier hat nur 1 oder 2 gebraucht...</p>
<p>ich denke das spricht für sich<br />
ok ich muss dazu sagen wurzel 9 -&gt; 2.99987324, aber es ging hierbei um eine möglichst schnelle und genau genügende funktion und man könnte noch ein oder 2 iterationen hinzufügen um genauer zu werden...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520299</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 31 May 2008 17:39:24 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 17:48:43 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>ich denke das spricht für sich</p>
</blockquote>
<p>Vor allem spricht es dafür, dass keine Ahnung hast, was da eigentlich gemessen wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520305</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 31 May 2008 17:48:43 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 19:36:00 GMT]]></title><description><![CDATA[<p>achja komm schon</p>
<p>wir wissen doch alle wie ich das meine oder?</p>
<p>wenn du auf die cpu ticks abzielst weiss ich sehr wohl bescheid...</p>
<p>naja ich hab meinen beitrag zum thema wurzeln geliefert und gut ist</p>
<p>die funktion hat vor(ungenauigkeit) und nachteile (schnelligkeit) aber sowas hat jede funktion...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520348</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 31 May 2008 19:36:00 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sat, 31 May 2008 20:09:46 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>wir wissen doch alle wie ich das meine oder?</p>
</blockquote>
<p><em>Ich</em> weiß nicht, was du meinst. Wenn zutreffen sollte, dass du meinst, was ich glaube dass du meinst, dann wage ich es, diese Aussage anzuzweifeln; solange du uns nicht ein Programm zeigst, dass genau dieses Verhalten hat + die Aussage, auf welchem System dieses Ergebnis erzielt wurde. Und auch dann werde ich dir wahrscheinlich (99%) zeigen können, dass das, was gemessen wurde, gerade nicht (bzw. nur zu einem unwesentlichen Teil) etwas mit der &quot;Geschwindigkeit&quot; von sqrt der Standardbibliothek zu tun hat.</p>
<p>Jedenfalls ist dein Beitrag hier ohne eine gewisse Qualifikation fehlplatziert und schlicht unseriös. Schlimmer: Neulinge tendieren dazu, sich gerade solchen Unfug als erstes anzueignen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520358</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 31 May 2008 20:09:46 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sun, 01 Jun 2008 10:45:21 GMT]]></title><description><![CDATA[<p>Ein kleiner Test (schnell hingeschrieben, deshalb viel c&amp;p) mit Visual C++ 2008 Express (/Ox /Ob2 /Oi /Ot /Oy /GT /GL /D &quot;WIN32&quot; /D &quot;NDEBUG&quot; /D &quot;_CONSOLE&quot; /D &quot;_UNICODE&quot; /D &quot;UNICODE&quot; /FD /EHsc /MT /GS-)<br />
Die Tests auf &lt;0 bzw. ==0 habe ich (zugunsten der Laufzeit der schnellen Wurzelfunktionen) weggelassen - ==0 ist nicht notwendig, &lt;0 überflüssig im Hinblick auf die Emulation von sqrt.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;ctime&gt;
#include &lt;float.h&gt;
using namespace std;

inline float FastWurzelExact1(float r)
{
    float Value = r;
    float halfValue = 0.5f*r;
    unsigned long* ptr = (unsigned long*)&amp;r;
    *ptr=(0xbe6f0000-*ptr)&gt;&gt;1;
    float temp1Wurzel = r;
    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;
    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;
    return Value*temp1Wurzel;
}
inline float FastWurzelExact2(const float&amp; r)
{

    const float halfValue = 0.5f*r;
    float temp1Wurzel = reinterpret_cast&lt;const float&amp;&gt;(static_cast&lt;const unsigned&amp;&gt;((0xbe6f0000u-reinterpret_cast&lt;const unsigned&amp;&gt;(r))&gt;&gt;1));
    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;
    temp1Wurzel *= 1.5f-temp1Wurzel*temp1Wurzel*halfValue;
    return r*temp1Wurzel;
}

typedef unsigned long long u64;

u64 rdtsc()
{
    __asm rdtsc;
}

void fast_state()
{
#if 0
    _controlfp(_PC_24,_MCW_PC);
#endif
}
void default_state()
{
#if 0
    _controlfp(_PC_64,_MCW_PC);
#endif
}

int main()
{
    const int repeat = 100000;
    const int inner = 100;
    float f = 0;
    srand(time(0));
    const int index[16] = { rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8,rand()%8 };
    const float x[16] = { rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f,rand()/13.f };
    fast_state();
    u64 best_fast = ~0ull;
    for ( int i = repeat; i--; )
    {
        u64 time = rdtsc();
        for ( int j = inner; j--; )
        {
            f += FastWurzelExact1( x[index[0&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[1&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[2&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[3&rsqb;&rsqb; );
            f += FastWurzelExact1( x[index[4&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[5&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[6&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[7&rsqb;&rsqb; );
            f += FastWurzelExact1( x[index[8&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[9&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[10&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[11&rsqb;&rsqb; );
            f += FastWurzelExact1( x[index[12&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[13&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[14&rsqb;&rsqb; ); f += FastWurzelExact1( x[index[15&rsqb;&rsqb; );
        }
        time = rdtsc() - time;
        if ( time &lt; best_fast )
        {
            best_fast = time;
            i = repeat;
            f = 0;
        }
    }
    default_state();
    cout &lt;&lt; &quot;Fast1:\t&quot; &lt;&lt; f &lt;&lt; '\t' &lt;&lt; FastWurzelExact1( x[index[0&rsqb;&rsqb; ) &lt;&lt; '\t' &lt;&lt;double(best_fast)/inner/16 &lt;&lt; endl;
    fast_state();
    u64 best_fast2 = ~0ull;
    for ( int i = repeat; i--; )
    {
        u64 time = rdtsc();
        for ( int j = inner; j--; )
        {
            f += FastWurzelExact2( x[index[0&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[1&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[2&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[3&rsqb;&rsqb; );
            f += FastWurzelExact2( x[index[4&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[5&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[6&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[7&rsqb;&rsqb; );
            f += FastWurzelExact2( x[index[8&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[9&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[10&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[11&rsqb;&rsqb; );
            f += FastWurzelExact2( x[index[12&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[13&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[14&rsqb;&rsqb; ); f += FastWurzelExact2( x[index[15&rsqb;&rsqb; );
        }
        time = rdtsc() - time;
        if ( time &lt; best_fast2 )
        {
            best_fast2 = time;
            i = repeat;
            f = 0;
        }
    }
    default_state();
    cout &lt;&lt; &quot;Fast2:\t&quot; &lt;&lt; f &lt;&lt; '\t' &lt;&lt; FastWurzelExact2( x[index[0&rsqb;&rsqb; ) &lt;&lt; '\t' &lt;&lt;double(best_fast2)/inner/16 &lt;&lt; endl;
    fast_state();
    u64 best = ~0ull;
    f = 0;
    for ( int i = repeat; i--; )
    {
        u64 time = rdtsc();
        for ( int j = inner; j--; )
        {
            f += sqrt( x[index[0&rsqb;&rsqb; ); f += sqrt( x[index[1&rsqb;&rsqb; ); f += sqrt( x[index[2&rsqb;&rsqb; ); f += sqrt( x[index[3&rsqb;&rsqb; );
            f += sqrt( x[index[4&rsqb;&rsqb; ); f += sqrt( x[index[5&rsqb;&rsqb; ); f += sqrt( x[index[6&rsqb;&rsqb; ); f += sqrt( x[index[7&rsqb;&rsqb; );
            f += sqrt( x[index[8&rsqb;&rsqb; ); f += sqrt( x[index[9&rsqb;&rsqb; ); f += sqrt( x[index[10&rsqb;&rsqb; ); f += sqrt( x[index[11&rsqb;&rsqb; );
            f += sqrt( x[index[12&rsqb;&rsqb; ); f += sqrt( x[index[13&rsqb;&rsqb; ); f += sqrt( x[index[14&rsqb;&rsqb; ); f += sqrt( x[index[15&rsqb;&rsqb; );
        }
        time = rdtsc() - time;
        if ( time &lt; best )
        {
            best = time;
            i = repeat;
            f = 0;
        }
    }
    default_state();
    cout &lt;&lt; &quot;sqrt:\t&quot; &lt;&lt; f &lt;&lt; '\t' &lt;&lt; sqrt( x[index[0&rsqb;&rsqb; ) &lt;&lt; '\t' &lt;&lt; double(best)/inner/16 &lt;&lt; endl;
}

#include &lt;windows.h&gt;

struct Affinity
{
    Affinity()
    {
        SetThreadAffinityMask(GetCurrentThread(),1);
        Sleep(1);
    }
} affinity;
</code></pre>
<p>zeigt mit verschiedenen von mir getesten Rechnern folgendes Verhalten:</p>
<pre><code>Fast1  Fast2  sqrt
Coppermine-P3         42,2   27,9    8,1
Northwood-P4          62,3   43,4   23,1
Merom-T7200           25,9   19,8    9,0
Palomino-Athlon XP    26,3   25,3   12,0
Winchester-Athlon 64  38,3   25,4   13,0
</code></pre>
<p>Angaben jeweils in Taktzyklen pro Aufruf (die Modifikation des Steuerwortes führt nur zu minimalen Änderungen beim Ergebnis)<br />
Daraus kann man <em>nicht</em> ableiten, dass dieses sog. schnelle Wurzelziehen irgendwie grundsätzlich schneller wäre. Bei mir ist es durchweg etwa halb so schnell (das Missverhältnis wird noch größer, wenn sse2-Instruktion verwendet werden auf Prozessoren, die das unterstützen). Es bedeutet aber auch nicht, dass sqrt <em>per se</em> schneller wäre - gerade bei einer inline-Funktion kann in einem bestimmten Programm durch den Scheduler oder ggf. den Prozessor (out of order execution) eine Menge Latenz verdeckt werden. Und schließlich kann das mit einem anderen Compiler oder auf einem anderen Rechner wieder ganz anders aussehen. Ohne ein paar Überlegungen in dieser Hinsicht lässt sich eben immer gerade das beweisen, was man glauben möchte, ganz unabhängig von einer möglicherweise existierenden objektiven Wahrheit. Womit dieses Thema hoffentlich erledigt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520491</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 01 Jun 2008 10:45:21 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Sun, 01 Jun 2008 11:42:15 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>naja das ist eine routine aus einem buch üebr 3d spiele programmierung</p>
</blockquote>
<p>und wie alt ist das buch? 15+ jahre?</p>
<blockquote>
<p>und so eine ähnliche wird in quake 3 verwendet</p>
</blockquote>
<p>q3 ist 10 jahre alt, und der code basiert wiederum auf noch viel älterem code.<br />
in der zwischenzeit hat sich viel getan bei den prozessoren.</p>
<p>es gibt wirklich keinen vernünftigen grund, ohne not solche hacks zu verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1520511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1520511</guid><dc:creator><![CDATA[pony reiten!]]></dc:creator><pubDate>Sun, 01 Jun 2008 11:42:15 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Wed, 27 Aug 2008 16:42:07 GMT]]></title><description><![CDATA[<p>pharmacy;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1572408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1572408</guid><dc:creator><![CDATA[jtsfds66]]></dc:creator><pubDate>Wed, 27 Aug 2008 16:42:07 GMT</pubDate></item><item><title><![CDATA[Reply to math.h zu langsam on Wed, 27 Aug 2008 17:46:48 GMT]]></title><description><![CDATA[<p>pharmacy;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1572499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1572499</guid><dc:creator><![CDATA[jtsfds248]]></dc:creator><pubDate>Wed, 27 Aug 2008 17:46:48 GMT</pubDate></item></channel></rss>