<?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[Benchmark float&#x2F;int]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>Ich habe mir spasseshalber ein Progrämmchen in C++ geschrieben, um die floating-point und Integer Rechenleistung meines betagten 550MHz Athlons zu messen. Für die Messung musste der Computer, für verschiedene Datentypen, die vier Grundrechenoperationen in einem Loop ausführen. Für das folgende Ergebnis wurden die Loops 100Mio mal durchlaufen:</p>
<p>char performance = 727.273 MIOPS<br />
short performance = 1025.64 MIOPS<br />
int performance = 727.273 MIOPS<br />
long performance = 1052.63 MIOPS<br />
float performance = 1025.64 MFLOPS<br />
double performance = 1052.63 MFLOPS<br />
long double performance = 1025.64 MFLOPS</p>
<p>Interessant finde ich, dass die Rechnungen mit char und int besonders langsam sind, jedoch die Berechnungen mit double sowie long double nicht langsamer als die mit float. Es würden mich eure Meinungen/Ideen dazu interessieren. <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>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;

// stopwatch class
class Stopwatch
{
    public:

        void Start(void);

        void Stop(void);

        double Show(void);

    private:

        clock_t m_start_time;
        clock_t m_stop_time;

    };

void Stopwatch::Start(void)
{
    m_start_time = clock();
    }

void Stopwatch::Stop(void)
{
    m_stop_time = clock();
    }

double Stopwatch::Show(void)
{
    return (double)(m_stop_time - m_start_time) / CLOCKS_PER_SEC;
    }

// benchmark template
template &lt;class T&gt;
double Benchmark(unsigned long loops)
{
    Stopwatch sw;

    sw.Start();

    T n;

    for(unsigned long i = 0; i &lt; loops; ++i)
    {
        n = 2;

        n *= 4;
        n += 7;
        n /= 3;
        n -= 1;

        }

    sw.Stop();

    // MFLOPS
    return ((loops * 4) / sw.Show()) / 1000000; 

    }

// main program
int main(int argc, char *argv[])
{

    fstream file(&quot;./benchmark.txt&quot;, ios::out);

    file &lt;&lt; &quot;char performance        = &quot; &lt;&lt; Benchmark&lt;char&gt;(100000000)          &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;short performance       = &quot; &lt;&lt; Benchmark&lt;short&gt;(100000000)         &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;int performance         = &quot; &lt;&lt; Benchmark&lt;int&gt;(100000000)           &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;long performance        = &quot; &lt;&lt; Benchmark&lt;long&gt;(100000000)          &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;float performance       = &quot; &lt;&lt; Benchmark&lt;float&gt;(100000000)         &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;double performance      = &quot; &lt;&lt; Benchmark&lt;double&gt;(100000000)        &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;long double performance = &quot; &lt;&lt; Benchmark&lt;long double&gt;(100000000)   &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;

    file.close();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/166166/benchmark-float-int</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 12:18:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/166166.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Nov 2006 20:32:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Sun, 26 Nov 2006 20:32:08 GMT]]></title><description><![CDATA[<p>Hallo zusammen</p>
<p>Ich habe mir spasseshalber ein Progrämmchen in C++ geschrieben, um die floating-point und Integer Rechenleistung meines betagten 550MHz Athlons zu messen. Für die Messung musste der Computer, für verschiedene Datentypen, die vier Grundrechenoperationen in einem Loop ausführen. Für das folgende Ergebnis wurden die Loops 100Mio mal durchlaufen:</p>
<p>char performance = 727.273 MIOPS<br />
short performance = 1025.64 MIOPS<br />
int performance = 727.273 MIOPS<br />
long performance = 1052.63 MIOPS<br />
float performance = 1025.64 MFLOPS<br />
double performance = 1052.63 MFLOPS<br />
long double performance = 1025.64 MFLOPS</p>
<p>Interessant finde ich, dass die Rechnungen mit char und int besonders langsam sind, jedoch die Berechnungen mit double sowie long double nicht langsamer als die mit float. Es würden mich eure Meinungen/Ideen dazu interessieren. <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>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;

// stopwatch class
class Stopwatch
{
    public:

        void Start(void);

        void Stop(void);

        double Show(void);

    private:

        clock_t m_start_time;
        clock_t m_stop_time;

    };

void Stopwatch::Start(void)
{
    m_start_time = clock();
    }

void Stopwatch::Stop(void)
{
    m_stop_time = clock();
    }

double Stopwatch::Show(void)
{
    return (double)(m_stop_time - m_start_time) / CLOCKS_PER_SEC;
    }

// benchmark template
template &lt;class T&gt;
double Benchmark(unsigned long loops)
{
    Stopwatch sw;

    sw.Start();

    T n;

    for(unsigned long i = 0; i &lt; loops; ++i)
    {
        n = 2;

        n *= 4;
        n += 7;
        n /= 3;
        n -= 1;

        }

    sw.Stop();

    // MFLOPS
    return ((loops * 4) / sw.Show()) / 1000000; 

    }

// main program
int main(int argc, char *argv[])
{

    fstream file(&quot;./benchmark.txt&quot;, ios::out);

    file &lt;&lt; &quot;char performance        = &quot; &lt;&lt; Benchmark&lt;char&gt;(100000000)          &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;short performance       = &quot; &lt;&lt; Benchmark&lt;short&gt;(100000000)         &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;int performance         = &quot; &lt;&lt; Benchmark&lt;int&gt;(100000000)           &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;long performance        = &quot; &lt;&lt; Benchmark&lt;long&gt;(100000000)          &lt;&lt; &quot; MIOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;float performance       = &quot; &lt;&lt; Benchmark&lt;float&gt;(100000000)         &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;double performance      = &quot; &lt;&lt; Benchmark&lt;double&gt;(100000000)        &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;
    file &lt;&lt; &quot;long double performance = &quot; &lt;&lt; Benchmark&lt;long double&gt;(100000000)   &lt;&lt; &quot; MFLOPS&quot; &lt;&lt; endl;

    file.close();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1181903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1181903</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 26 Nov 2006 20:32:08 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Sun, 26 Nov 2006 20:40:38 GMT]]></title><description><![CDATA[<p>Stöffel schrieb:</p>
<blockquote>
<p>Interessant finde ich, dass die Rechnungen mit char und int besonders langsam sind...</p>
</blockquote>
<p>in der tat sehr merkwürdig.<br />
in der 'benchmark' funktion wird ja mit konstanten gerechnet, änder' das mal in irgendwas variables, damit dein compiler das nicht optimieren kann...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1181906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1181906</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Sun, 26 Nov 2006 20:40:38 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Sun, 26 Nov 2006 20:43:13 GMT]]></title><description><![CDATA[<blockquote>
<p>olaf@pc:~/test$ g++ test.cpp<br />
olaf@pc:~/test$ ./a.out<br />
char performance = 177.778 MIOPS<br />
short performance = 177.778 MIOPS<br />
int performance = 198.02 MIOPS<br />
long performance = 190.476 MIOPS<br />
float performance = 216.216 MFLOPS<br />
double performance = 209.424 MFLOPS<br />
long double performance = 45.4545 MFLOPS<br />
olaf@pc:~/test$ g++ -O3 test.cpp<br />
olaf@pc:~/test$ ./a.out<br />
char performance = inf MIOPS<br />
short performance = inf MIOPS<br />
int performance = inf MIOPS<br />
long performance = inf MIOPS<br />
float performance = inf MFLOPS<br />
double performance = inf MFLOPS<br />
long double performance = inf MFLOPS</p>
</blockquote>
<p>du wirst mit deinem programm keine brauchbaren ergebnisse erzielen, es kommt halt ganz drauf an was dein compiler alles so optimiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1181909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1181909</guid><dc:creator><![CDATA[borg]]></dc:creator><pubDate>Sun, 26 Nov 2006 20:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Sun, 26 Nov 2006 23:47:37 GMT]]></title><description><![CDATA[<p>Du solltest mindestens 2 Modifikationen machen:</p>
<ol>
<li>
<p>Ermittle den Wert von &quot;loops&quot; zur Laufzeit - lies den aus einem Textfile oder sowas. So dass der Compiler den Wert zur Compilezeit eben nicht wissen kann. Das sorgt schonmal dafür dass das Ergebnis der Schleife nicht zur Compilezeit ermittelt werden kenn.</p>
</li>
<li>
<p>Übergib das Ergebnis einer Funktion die der Compiler nicht kennt bzw. nicht wegoptimieren kann. Dazu eignet sich unter Windows z.B. WriteDebugString oder du kannst den Wert auch einfach mit ausgeben lassen (in das Textfile/den cout Stream/...). Das sorgt dafür dass der Compiler nicht die ganze Berechnung aus der Schleife rausnehmen kann, weil das Ergebnis ja verwendet wird.</p>
</li>
</ol>
<p>Das Programm so wie es ist würde dir ein wirklich guter Compiler &quot;zu nichts&quot; optimieren <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 />
EDIT: genau das hat der gcc mit -O3 anscheinend gemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1181982</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1181982</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 26 Nov 2006 23:47:37 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 07:12:29 GMT]]></title><description><![CDATA[<p>Hmja, ein Ergebnis von Unendlich spricht wohl schon dafür, dass der ganze Loop wegoptimiert wurde. Ich hatte gehofft dass der Compiler nicht clever genug ist, um zu sehen dass die Berechnungen eigentlich überflüssig sind. Ich werde mal einen Versuch machen, wo die Variable einen zufälligen Anfangswert hat und nicht in jedem Loopdurchlauf neu initialisiert wird und das Resultat dann auch zurück gegeben wird. Mal sehen. Danke für eure Antworten. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182014</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 27 Nov 2006 07:12:29 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 17:07:13 GMT]]></title><description><![CDATA[<p>schaltet doch einfach die Optimierung aus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182535</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Mon, 27 Nov 2006 17:07:13 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 17:42:38 GMT]]></title><description><![CDATA[<p>Das macht den Vergleich aber nicht unbedingt deutlich aussagekräftiger. Tests sollten unter möglichst realen Bedingungen laufen. Keine Optimierungen ist imho nicht sehr real <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/1182556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182556</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 27 Nov 2006 17:42:38 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 17:46:09 GMT]]></title><description><![CDATA[<p>TactX schrieb:</p>
<blockquote>
<p>Das macht den Vergleich aber nicht unbedingt deutlich aussagekräftiger. Tests sollten unter möglichst realen Bedingungen laufen. Keine Optimierungen ist imho nicht sehr real <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>
</blockquote>
<p>naja, aber in dem fall will er ja nicht wissen wie toll und schnell sein programm läuft, sondern wie viel zeit die berechnungen verbraten...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182559</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Mon, 27 Nov 2006 17:46:09 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 17:52:45 GMT]]></title><description><![CDATA[<p>Aber eben die Berechnungen werden ja auch durch die Optimierung beeinflusst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182562</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 27 Nov 2006 17:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 17:59:12 GMT]]></title><description><![CDATA[<p>TactX schrieb:</p>
<blockquote>
<p>Aber eben die Berechnungen werden ja auch durch die Optimierung beeinflusst.</p>
</blockquote>
<p>aber eben deshalb muss man auch dafür sorgen, dass nix optimiert werden kann...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182567</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Mon, 27 Nov 2006 17:59:12 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 18:22:12 GMT]]></title><description><![CDATA[<p>Also testen wir Berechnungen unter vollkommen unrealistischen Bedingungen um was rauszufinden? Die Vorteile der CPUs die ja teilweise nur in &quot;realem&quot; Code zum tragen kommen fliessen hier ja nicht ein. Ich sehe den Sinn einfach nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182596</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 27 Nov 2006 18:22:12 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 18:32:42 GMT]]></title><description><![CDATA[<p>TactX schrieb:</p>
<blockquote>
<p>Die Vorteile der CPUs die ja teilweise nur in &quot;realem&quot; Code zum tragen kommen fliessen hier ja nicht ein.</p>
</blockquote>
<p>guck doch mal seine 'benchmark' funktion.<br />
ein aggressiv optimierender compiler compiliert die zu *nichts*<br />
es gibt da zwar 'realen' sourcecode, aber den kann er auch gleich in /* */ einpacken <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/1182605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182605</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Mon, 27 Nov 2006 18:32:42 GMT</pubDate></item><item><title><![CDATA[Reply to Benchmark float&#x2F;int on Mon, 27 Nov 2006 18:46:14 GMT]]></title><description><![CDATA[<p>net schrieb:</p>
<blockquote>
<p>TactX schrieb:</p>
<blockquote>
<p>Die Vorteile der CPUs die ja teilweise nur in &quot;realem&quot; Code zum tragen kommen fliessen hier ja nicht ein.</p>
</blockquote>
<p>guck doch mal seine 'benchmark' funktion.<br />
ein aggressiv optimierender compiler compiliert die zu *nichts*</p>
</blockquote>
<p>Klar. Ich meine ja nur, dass man sowas eh nur mit einem etwas besseren/realeren Test einigermassen aussagekräftig testen kann. Der Test wird ja nicht wirklich sinnvoller nur weil man das komplette Wegoptimieren unterbindet. Wenn eh nur die einzelnen Laufzeiten der ALU/FPU-Befehle interessieren, kann eh ins Manual schauen. Alle anderen Effekte (Pipelining, Caching, SIMD, whatever) scheinen euch ja nicht zu kehren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1182625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1182625</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 27 Nov 2006 18:46:14 GMT</pubDate></item></channel></rss>