<?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>benchamark | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/benchamark/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, 03 Feb 2021 10:52:45 +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>benchamark | 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>So I timed a short program with /Gd and /Gr</title>
		<link>https://learncgames.com/so-i-timed-a-short-program-with-gd-and-gr/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-i-timed-a-short-program-with-gd-and-gr</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 04 Feb 2021 00:00:30 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[benchamark]]></category>
		<category><![CDATA[Timings]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2600</guid>

					<description><![CDATA[<p>This was the follow up to yesterday&#8217;s post about seeing if changing the function calling convention, switching from stacked parameters to passing them in registers made a difference in execution time. This was the program I used. #include &#60;stdio.h&#62; #include &#34;hr_time.h&#34; int add(int a, int b, int c,int d,int e) { return a - b [&#8230;]</p>
The post <a href="https://learncgames.com/so-i-timed-a-short-program-with-gd-and-gr/">So I timed a short program with /Gd and /Gr</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;:204,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/jarmoluk-143740\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=259303&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251208213526\/https:\/\/pixabay.com\/users\/jarmoluk-143740\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:44:31&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 03:42:55&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-25 05:08:27&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 02:03:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-17 18:06:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 04:41:59&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 04:41:59&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:205,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=259303&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:44:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 03:42:53&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-25 05:08:27&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 02:03:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-17 18:06:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 04:41:58&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 04:41:58&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:13,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250807013721\/https:\/\/github.com\/David-H-Bolton\/LearnC&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:16&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:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:31&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:25&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:11&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:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:50&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 22:49:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 04:18:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 04:19:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 09:53:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 10:17:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 13:35:54&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 15:50:44&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:206,&quot;href&quot;:&quot;https:\/\/www.extremetech.com\/extreme\/188776-how-l1-and-l2-cpu-caches-work-and-why-theyre-an-essential-part-of-modern-chips&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260102003400\/https:\/\/www.extremetech.com\/extreme\/188776-how-l1-and-l2-cpu-caches-work-and-why-theyre-an-essential-part-of-modern-chips&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:45:16&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-25 05:08:27&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 20:09:33&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 02:03:13&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-05 02:03:13&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2601" aria-describedby="caption-attachment-2601" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-2601" src="https://learncgames.com/wp-content/uploads/2021/02/stopwatch-259303_640-300x201.jpg" alt="StopWatch timings" width="300" height="201" srcset="https://learncgames.com/wp-content/uploads/2021/02/stopwatch-259303_640-300x201.jpg 300w, https://learncgames.com/wp-content/uploads/2021/02/stopwatch-259303_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-2601" class="wp-caption-text">Image by <a href="https://pixabay.com/users/jarmoluk-143740/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=259303">Michal Jarmoluk</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=259303">Pixabay</a></figcaption></figure>
<p>This was the follow up to yesterday&#8217;s post about seeing if changing the function calling convention, switching from stacked parameters to passing them in registers made a difference in execution time.</p>
<p>This was the program I used.</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;
#include &quot;hr_time.h&quot;

int add(int a, int b, int c,int d,int e) {
	return a - b * 2 + c * 3 + d * 3 + e * 5;
}

int __cdecl main() {
	int total=0;
	stopWatch s;
	startTimer(&amp;s);
	for (int i = 0; i &lt; 10000000; i++) {
		total += add(i, 5, 6, i, 8);
	}
	stopTimer(&amp;s);
	printf(&quot;Value = %d Time = %7f.5\n&quot;,total, getElapsedTime(&amp;s));
}</code></pre>
<p>Pretty similar to the one I did yesterday except with two more parameters in the add function and my Windows high-res timing code. I&#8217;ve extracted the two timing files (hr_time.h/.c) from the asteroids and it&#8217;s in the <a title="Link to LearnC on GitHub" href="https://github.com/David-H-Bolton/LearnC" target="_blank" rel="nofollow noopener">LearnC folder on GiHhub</a>.</p>
<p>As before this was compiled as x86. Also I tried it first compiled as release. This means the optimizing compiler has its way and I got virtually identical for <strong>cdecl</strong> (/Gd), <strong>fastcall</strong> (/Gr) and even <strong>safecall</strong> (/Gz).</p>
<p>Disassembly of the machine code revealed that the optimizer had moved the function code inline in the for loop and this negated the call code. So I did it again in debug mode. Here there was a clear difference. The times for fastcall were 0.259 while the cdecl (the default) was 0.239 which is about an 8% speed increase. Safecall was roughly the same execution as cdecl. So the lesson seem to be don&#8217;t use fastcall.</p>
<p>I think I need a more complicated program which should be compiled in release mode but where optimization doesn&#8217;t transform the function into inline code. Perhaps making the function longer would do it so the function machine code would be too long to fit in <a title="Link to what is a L1 cache" href="https://www.extremetech.com/extreme/188776-how-l1-and-l2-cpu-caches-work-and-why-theyre-an-essential-part-of-modern-chips" target="_blank" rel="nofollow noopener">a L1 cache.</a></p>
<p>Interestingly the release code execution time was 0.005557 seconds, almost 50 x faster than the debug time.</p>The post <a href="https://learncgames.com/so-i-timed-a-short-program-with-gd-and-gr/">So I timed a short program with /Gd and /Gr</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">2600</post-id>	</item>
	</channel>
</rss>
