<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>time | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/time/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Wed, 11 Mar 2020 19:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>time | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Other ways to time code</title>
		<link>https://learncgames.com/other-ways-to-time-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=other-ways-to-time-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 15 Mar 2020 00:00:28 +0000</pubDate>
				<category><![CDATA[SDL]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[time]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=125</guid>

					<description><![CDATA[<p>As well as the hr_time code that I used in discussion of sdldemo SDL itself provides some other ways to time. If you are happy with millisecond level accuracy of timing, just call this function which returns an unsigned 32-bit (i.e. 0- 4 billion) giving the number of milliseconds since the SDL library was initialised. [&#8230;]</p>
The post <a href="https://learncgames.com/other-ways-to-time-code/">Other ways to time code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:819,&quot;href&quot;:&quot;https:\/\/pixabay.com\/photos\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:820,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:821,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29#SDL_GetTicks-1&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20210917191444\/http:\/\/wiki.libsdl.org\/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL3\/SDL_GetTicks&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:822,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20220524122630\/http:\/\/wiki.libsdl.org\/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:37:15&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-02-06 19:37:15&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:823,&quot;href&quot;:&quot;http:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20220524111032\/http:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29&quot;,&quot;redirect_href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL_GetPerformanceFrequency?highlight=(\\bCategoryTimer\\b)|(CategoryEnum)|(CategoryStruc)&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_129" aria-describedby="caption-attachment-129" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="wp-image-129 size-medium" src="https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-300x200.jpg" alt="Stop Watch photo from Pixabay" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-1024x682.jpg 1024w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280-768x512.jpg 768w, https://learncgames.com/wp-content/uploads/2020/03/time-731110_1280.jpg 1280w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-129" class="wp-caption-text">Image by <a href="https://pixabay.com/photos/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110">Free-Photos</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=731110">Pixabay</a></figcaption></figure>
<p>As well as the hr_time code that I used in <a href="https://learncgames.com/the-joys-of-linux-c-compilation/" target="_blank" rel="noopener noreferrer">discussion of sdldemo</a> SDL itself provides some other ways to time. If you are happy with millisecond level accuracy of timing, just call this function which returns an unsigned 32-bit (i.e. 0- 4 billion) giving the number of milliseconds since the SDL library was initialised.</p>
<p><a href="http://wiki.libsdl.org/SDL_GetTicks?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29#SDL_GetTicks-1" target="_blank" rel="noopener noreferrer">SDL_GetTicks()</a></p>
<p>The link goes to the Wiki page on libsdl.org  for SDL_GetTicks().</p>
<p>As always, call it twice, once to get the start value and once to get the stop then subtract start from stop to get the elapsed time in milliseconds..</p>
<p>For some operations this can be easier to use. A frame is 16.666666 milliseconds so if your code runs in less than 16 milliseconds, it&#8217;s not going to cause problems. In my original Windows code, it ran is a fraction of a millisecond. Compiled C code really is fast and helped because the GPU is doing most of the donkey work!</p>
<p>There&#8217;s also a higher accuracy timer. This I guess is just a wrapper round the system call I call in hr_time.</p>
<p id="CA-pygments_173" dir="ltr" lang="en"><a href="http://wiki.libsdl.org/SDL_GetPerformanceCounter?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29" target="_blank" rel="noopener noreferrer"><span class="line"><span class="n">Uint64</span> <span class="n">SDL_GetPerformanceCounter</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span></span></a><br />
Which I haven&#8217;t used yet but which I guess returns a processor clock count. To measure time you need to call it twice (start and stop values as before) then divide by the frequency value returned from a call to</p>
<p id="CA-pygments_245" dir="ltr" lang="en"><a href="http://wiki.libsdl.org/SDL_GetPerformanceFrequency?highlight=%28%5CbCategoryTimer%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruc%29" target="_blank" rel="noopener noreferrer"><span class="line"><span class="n">Uint64</span> <span class="n">SDL_GetPerformanceFrequency</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span></span></a></p>
<p dir="ltr" lang="en">My computer returns a clock frequency of 3,500,000,000 clocks per second but the actual value is irrelevant just divide ((stop &#8211; start)/ frequency) to get the elapsed time in seconds.</p>
<p dir="ltr" lang="en">The post <a href="https://learncgames.com/other-ways-to-time-code/">Other ways to time code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">125</post-id>	</item>
	</channel>
</rss>
