<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>How much time</title>
		<link>http://www.allegro.cc/forums/view/589462</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 08 Jan 2007 02:56:02 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi!</p><p>I&#39;m new to allegro and now I have the first problem that I can&#39;t bring away myself.<br />So my question is very simple:<br />How can I read the time something takes? <br />example:<br />I have the following code: </p><p>//Here I want to start the timer</p><p>//...code...</p><p>//and here I want to know how much time is left since I started the timer.</p><p>How can I do this?<br />I looked in the Manual and the forum search but I did not find anything what helped me. (Maybe I did not find it because of my English...)</p><p>Thank you,</p><p>Decelion</p><p>PS: Sorry for my English being not very good sometimes, I am from Germany. If you find mistakes, please tell me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Decelion)</author>
		<pubDate>Sun, 07 Jan 2007 17:29:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can use the clock() function from time.h to check the duration.
</p><div class="source-code snippet"><div class="inner"><pre>clock_t start <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_103.html" target="_blank">clock</a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
clock_t end<span class="k2">;</span>
<span class="c">/*</span>
<span class="c">Do whatever you need to check the duration of here</span>
<span class="c">*/</span>
end <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_103.html" target="_blank">clock</a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// Calculate the duration in seconds</span>
duration<span class="k3">=</span><span class="k2">(</span><span class="k1">double</span><span class="k2">)</span><span class="k2">(</span>stop-start<span class="k2">)</span><span class="k3">/</span>CLOCKS_PER_SEC<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ixilom)</author>
		<pubDate>Sun, 07 Jan 2007 17:52:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, you could use allegro timer stuff:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">// make this global</span></td></tr><tr><td class="number">2</td><td><span class="k1">unsigned</span> <span class="k1">int</span> my_time<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="c">// your timer function</span></td></tr><tr><td class="number">5</td><td><span class="k1">void</span> my_timer_f<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span></td></tr><tr><td class="number">6</td><td><span class="k2">{</span></td></tr><tr><td class="number">7</td><td>    my_time<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td><span class="k2">}</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td><span class="c">// f.i. in main()</span></td></tr><tr><td class="number">12</td><td><a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td><a href="http://www.allegro.cc/manual/install_int" target="_blank"><span class="a">install_int</span></a><span class="k2">(</span>my_timer_f, <span class="n">1</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// Your timer function will run once every millisecond</span></td></tr><tr><td class="number">14</td><td>my_time <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td><span class="c">// then to your code:</span></td></tr><tr><td class="number">19</td><td><span class="c">//Here I want to start the timer</span></td></tr><tr><td class="number">20</td><td><span class="k1">unsigned</span> <span class="k1">int</span> start_time <span class="k3">=</span> my_time<span class="k2">;</span></td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td><span class="c">//...code...</span></td></tr><tr><td class="number">23</td><td>&#160;</td></tr><tr><td class="number">24</td><td><span class="c">//and here I want to know how much time is left since I started the timer.</span></td></tr><tr><td class="number">25</td><td><span class="k1">unsigned</span> <span class="k1">int</span> time_used <span class="k3">=</span> my_time <span class="k3">-</span> start_time<span class="k2">;</span> <span class="c">// in milliseconds</span></td></tr></tbody></table></div></div><p>

What happens is you 
</p><ul><li><p>initialize the timer stuff</p></li><li><p>create a function that increments a global int variable</p></li><li><p>set this function to run f.i. once every millisecond</p></li><li><p>read the global variable anytime you want</p></li></ul><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Sun, 07 Jan 2007 17:57:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want to time how long the program takes to execute (which you probably don&#39;t. You&#39;re probably doing a fps count), you can execute it with time.</p><p>Instead of &#39;myprogram&#39;, you type &#39;time myprogram&#39;, and it will tell you the time at the bottom.</p><p>I don&#39;t think Windows has this, though, so if you want to be portable use Allegro timers.</p><p>EDIT:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
<span class="source-code"><span class="k1">unsigned</span> <span class="k1">int</span> my_time<span class="k2">;</span></span>
</p></div></div><p>
Doesn&#39;t it need to be volatile?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Sun, 07 Jan 2007 18:08:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, thank you very much!<br />Now I can go on making Doom 4 <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Decelion)</author>
		<pubDate>Sun, 07 Jan 2007 18:19:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Doesn&#39;t it need to be volatile?
</p></div></div><p>
Yes, I think so. Just for sure. If you have heavy optimization on, your compiler might make your application reuse the memory space of the variable, if you don&#39;t declare it volatile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Sun, 07 Jan 2007 18:57:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Ok, thank you very much!<br />Now I can go on making Doom 4 <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div></div><p>

L0L, a sense of humor is very important, good luck!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Sun, 07 Jan 2007 23:34:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Profiling can be useful too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Mon, 08 Jan 2007 02:56:02 +0000</pubDate>
	</item>
</rss>
