<?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>postinc | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/postinc/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, 17 Mar 2021 11:32:40 +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>postinc | 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>Is variable++ faster than ++variable?</title>
		<link>https://learncgames.com/is-variable-faster-than-variable/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=is-variable-faster-than-variable</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 19 Mar 2021 00:00:48 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[postinc]]></category>
		<category><![CDATA[preinc]]></category>
		<category><![CDATA[Timings]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2908</guid>

					<description><![CDATA[<p>One of the things I as told when I learnt C++ and then later C was that a post-inc (i.e. variable++) was faster than a pre-inc i.e. ++variable. Frankly I&#8217;m not sure if it is really true but its not a difficult thing to test. Here&#8217;s a short program #include &#60;stdio.h&#62; #include &#34;hr_time.h&#34; #define NUMLOOPS [&#8230;]</p>
The post <a href="https://learncgames.com/is-variable-faster-than-variable/">Is variable++ faster than ++variable?</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;:14,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250213114627\/https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 18:24:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:16:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 22:22:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 04:17:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:17:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 04:22:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 04:38:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 08:48:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 09:17:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 10:18:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:14:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 16:38:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 19:05:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 19:29:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 21:51:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 22:18:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 22:18:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 22:20:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 07:27:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img fetchpriority="high" decoding="async" class="alignleft wp-image-2913 size-full" src="https://learncgames.com/wp-content/uploads/2021/03/timings-1.png" alt="Timings" width="382" height="378" srcset="https://learncgames.com/wp-content/uploads/2021/03/timings-1.png 382w, https://learncgames.com/wp-content/uploads/2021/03/timings-1-300x297.png 300w" sizes="(max-width: 382px) 100vw, 382px" />One of the things I as told when I learnt C++ and then later C was that a post-inc (<em>i.e. variable++</em>) was faster than a pre-inc i.e. ++variable. Frankly I&#8217;m not sure if it is really true but its not a difficult thing to test.</p>
<p>Here&#8217;s a short program</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;
#include &quot;hr_time.h&quot;

#define NUMLOOPS 100000000

int main() {
  stopWatch s;
  startTimer(&amp;s);
  int j=0;
  for (int i=0;i&lt;NUMLOOPS;i++){
    ++j;
  }
  stopTimer(&amp;s);
  printf(&quot;PreInc = %10.5f\n&quot;,diff(&amp;s));

  startTimer(&amp;s);   
  j=0;
  for (int i=0;i&lt;NUMLOOPS;i++){
    j--;
  }
  stopTimer(&amp;s);
  printf(&quot;PostInc = %10.5f\n&quot;,diff(&amp;s));  
}</code></pre>
<p>You can get the siurce code including hr_time.h and .c from the timings.zip file on <a title="Link to Learn C on Linux on GitHub" href="https://github.com/David-H-Bolton/LearnCOnLinux" target="_blank" rel="nofollow noopener">GitHub</a>. I used VS Code with clang to build this on Ubuntu. Here is the tasks.json file to build it. It assumes that the file is in your workspace folder and creates a file called ex1. The timings.zip file contains the json files as well.</p>
<pre><code class="language-json" data-line="">{
    &quot;version&quot;: &quot;2.0.0&quot;,
    &quot;tasks&quot;: [
        {
            &quot;type&quot;: &quot;shell&quot;,
            &quot;label&quot;: &quot;clang build active file&quot;,
            &quot;command&quot;: &quot;/usr/bin/clang&quot;,
            &quot;args&quot;: [
                &quot;-g&quot;,
                &quot;${file}&quot;,&quot;${workspaceFolder}/hr_time.c&quot;,              
                &quot;-o&quot;,
                &quot;${fileDirname}/ex1&quot;,                
                &quot;-lm&quot;
            ],
            &quot;options&quot;: {
                &quot;cwd&quot;: &quot;/usr/bin&quot;
            },
            &quot;group&quot;: {
                &quot;kind&quot;: &quot;build&quot;,
                &quot;isDefault&quot;: true
            }
        }
    ]
}</code></pre>
<p>Ignore the first three runs which were for 10 million not 100 million. All do indeed show that <strong>post-inc</strong> is indeed faster. Not by a great margin but each of the last 100 million loops takes between 94% and 96% of the <strong>preinc</strong> time.</p>The post <a href="https://learncgames.com/is-variable-faster-than-variable/">Is variable++ faster than ++variable?</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">2908</post-id>	</item>
	</channel>
</rss>
