<?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[&amp;lt;ctime&amp;gt; und std::clock Problem]]></title><description><![CDATA[<p>Da sich ei meinem Programm der Wert von std::clock() nicht geändert habe, habe ich versucht das ganze Problem zu lösen.</p>
<p>Scheinbar gibt clock() nicht</p>
<p><a href="http://c-plusplus.com" rel="nofollow">http://c-plusplus.com</a> schrieb:</p>
<blockquote>
<p>The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.)</p>
</blockquote>
<p>zurück, sondern nur die Zeit, die Mein Programm gelaufen ist.</p>
<p>(Der Wert erhöht sich ganz normal wenn ich das usleep(20); aus dem Code nehme)</p>
<p>Ist das Verhalten normal? Überhaupt zulässig?</p>
<pre><code>$ g++ --version
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright (C) 2006 Free Software Foundation, Inc.
Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.
</code></pre>
<p>Oder liegt da ein Compilerproblem vor?</p>
<p>Testcode</p>
<pre><code>$ cat main.cpp
#include &lt;iostream&gt;
#include &lt;ctime&gt;

int main()
{
        while (1)
        {
                static std::clock_t start(std::clock());

                std::clock_t actual(std::clock());

                std::cout &lt;&lt; start &lt;&lt; &quot; &quot; &lt;&lt; actual &lt;&lt; &quot; &quot; &lt;&lt; actual - start &lt;&lt; std::endl;

                usleep(20);//Auskommentieren zum test
        }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/195053/lt-ctime-gt-und-std-clock-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 23:20:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195053.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 13 Oct 2007 12:55:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 12:55:26 GMT]]></title><description><![CDATA[<p>Da sich ei meinem Programm der Wert von std::clock() nicht geändert habe, habe ich versucht das ganze Problem zu lösen.</p>
<p>Scheinbar gibt clock() nicht</p>
<p><a href="http://c-plusplus.com" rel="nofollow">http://c-plusplus.com</a> schrieb:</p>
<blockquote>
<p>The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.)</p>
</blockquote>
<p>zurück, sondern nur die Zeit, die Mein Programm gelaufen ist.</p>
<p>(Der Wert erhöht sich ganz normal wenn ich das usleep(20); aus dem Code nehme)</p>
<p>Ist das Verhalten normal? Überhaupt zulässig?</p>
<pre><code>$ g++ --version
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright (C) 2006 Free Software Foundation, Inc.
Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.
</code></pre>
<p>Oder liegt da ein Compilerproblem vor?</p>
<p>Testcode</p>
<pre><code>$ cat main.cpp
#include &lt;iostream&gt;
#include &lt;ctime&gt;

int main()
{
        while (1)
        {
                static std::clock_t start(std::clock());

                std::clock_t actual(std::clock());

                std::cout &lt;&lt; start &lt;&lt; &quot; &quot; &lt;&lt; actual &lt;&lt; &quot; &quot; &lt;&lt; actual - start &lt;&lt; std::endl;

                usleep(20);//Auskommentieren zum test
        }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1384376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384376</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 13 Oct 2007 12:55:26 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 13:10:33 GMT]]></title><description><![CDATA[<p>Öhm, clock() soll die Zeit zurück liefern, seitdem das Programm gestartet wurde. Und nach dem was du da schreibst, tut es das auch. Wo ist denn das Problem?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384390</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Sat, 13 Oct 2007 13:10:33 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 13:14:15 GMT]]></title><description><![CDATA[<p>darthdespotism schrieb:</p>
<blockquote>
<p>Scheinbar gibt clock() nicht</p>
<p><a href="http://c-plusplus.com" rel="nofollow">http://c-plusplus.com</a> schrieb:</p>
<blockquote>
<p>The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.)</p>
</blockquote>
</blockquote>
<p>Google-Überstzer ist dein Freund:</p>
<blockquote>
<p>Die Uhr () Funktion liefert den Prozessor Zeit, da das Programm gestartet wurde, oder -1, wenn diese Information nicht verfügbar ist. Für die Konvertierung der Rückgabewert auf Sekunden, teilen sie durch CLOCKS_PER_SEC. (Hinweis: Wenn Sie Ihre Compiler POSIX-kompatibel ist, dann ist immer CLOCKS_PER_SEC definiert als 1000000.)</p>
</blockquote>
<p>lol, ich liebe solche Übersetzungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384392</guid><dc:creator><![CDATA[Don06]]></dc:creator><pubDate>Sat, 13 Oct 2007 13:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 13:18:37 GMT]]></title><description><![CDATA[<p>Vielleicht hab ich das nicht klar genug ausgedrück.</p>
<p>Ich hatte von clock() erwartet, die Zeit zu liefern, seit das Programm gestartet wurde und nicht, was aktuell der Fall ist, die Zeit, die das Programm gelaufen ist (und nicht geschlafen hat)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384397</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 13 Oct 2007 13:18:37 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 13:25:17 GMT]]></title><description><![CDATA[<p>Unter Windows mit ::Sleep(...) funktioniert das einwandfrei. Setze ich zB ::Sleep(500) ein wird wird</p>
<pre><code>500
1000
1500
2000
usw.
</code></pre>
<p>ausgegeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1384404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384404</guid><dc:creator><![CDATA[Don06]]></dc:creator><pubDate>Sat, 13 Oct 2007 13:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Sat, 13 Oct 2007 13:31:34 GMT]]></title><description><![CDATA[<p>Ja, genau das hätte ich erwartet, bekomme aber nur</p>
<pre><code>0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1384407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1384407</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Sat, 13 Oct 2007 13:31:34 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;ctime&amp;gt; und std::clock Problem on Mon, 15 Oct 2007 06:54:30 GMT]]></title><description><![CDATA[<p>clock() liefert afaik nur die Zeit, in der das Programm auch selbst den Prozessor hatte - und bei usleep() gibt es den Prozessor ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1385300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1385300</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 15 Oct 2007 06:54:30 GMT</pubDate></item></channel></rss>