<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Why does my C program run faster on Linux than on Windows?</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Thu, 23 May 2013 17:51:54 GMT</pubDate>
	<lastBuildDate>Thu, 23 May 2013 17:51:54 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>39</c9:totalResults>
	<c9:pageCount>-39</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>Last November, I wrote a C program that can find large prime numbers (using the Lucas Lehmer test for mersenne prime numbers). Today, I installed Ubuntu 6.10 LTS in Microsoft Virtual PC 2007 and proceeded to install gcc, m4, autoconf and gmp. I also installed
 all of the patches available for Ubuntu and upgraded the kernel to the i686 version.<br /><br />I downloaded the source code for my program from my university's unix server using sch and compiled my program using GCC. Imagine my surprise when I discovered that my program executed in a Virtual PC far faster than it executes on Windows.<br /><br />Here are some numbers:<br /><br />Testing all of the mersenne numbers ((2^x) - 1) between 0 and 2281 takes 1 second on Ubuntu and 3 seconds on windows. Testing all of the mersenne numbers between 0 and 3217 takes 5 seconds on Ubuntu and 10 seconds on Windows. Testing M21701 ((2^21701) - 1)
 takes 6 seconds on Ubuntu and 20 seconds on Windows.<br /><br />You could say that my program runs twice as fast on Ubuntu, but that would be wrong, because Microsoft Virtual PC does not have SMP support, so my these tests are being run in a single thread on Ubuntu and two threads on Windows (three if you include the main
 thread that waits for the other threads to terminate) with the exception of the test of M21701, which uses a single thread on both.<br /><br />Since I am using win32-pthreads for multithreading, I decided to do another run that would eliminate shared resources between the threads as a source of overhead by ensuring that each thread had a ton of work to do before needing to lock the mutex. So I tested
 all of the mersenne numbers between 2281 and 3217. It took 4 seconds on Ubuntu and 7 seconds on Windows.<br /><br />The variables here are the operating systems and the compilers. I am running Windows Media Center 2005 Edition with Visual Studio 2008 Professional and under Microsoft Virtual PC 2007, Ubuntu 6.10 LTS with GCC 4.03. I am compiling my program in Visual Studio
 2008 Professional under release mode with all compilation flags that I could find set. That includes /Ox, /Ob2, /Ot, /Oy, /GL, /arch:SSE2, /fp:fast and /GS-. I am compiling my program on Ubuntu with the following command:<br /><br />gcc -m32 -O2 -fomit-frame-pointer -mtune=k8 -march=k8 mersenne.c /usr/local/lib/gmp.so<br /><br />There are no background processes running that are sucking up CPU resources and I did each test (particularly on Windows) several times to try to minimize the negativity of the results.<br /><br />The code is the same and the hardware is the same. The only other variable is Virtual PC, which should be harming performance on Ubuntu, not Windows. So would anyone be able to tell me, exactly what is making my program run so much slower on Windows than it
 runs on Ubuntu?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/261385#261385</link>
		<pubDate>Sat, 01 Mar 2008 23:49:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/261385#261385</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>I don't know if this is the answer, but in both cases, the hardware is definitely&nbsp;NOT the same.<br /><br />Your Windows install may have some driver that is slowing it down that the Ubuntu doesn't have because it's running on virtualized hardware.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/d94e71096d9446ad89139dfa00c0546e#d94e71096d9446ad89139dfa00c0546e</link>
		<pubDate>Sun, 02 Mar 2008 00:44:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/d94e71096d9446ad89139dfa00c0546e#d94e71096d9446ad89139dfa00c0546e</guid>
		<dc:creator>RichA</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/RichA/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">RichA wrote:</div>
<div class="quoteBody">&#65279;
<p>I don't know if this is the answer, but in both cases, the hardware is definitely&nbsp;NOT the same.<br /><br />Your Windows install may have some driver that is slowing it down that the Ubuntu doesn't have because it's running on virtualized hardware.</p>
</div>
</blockquote>
<br /><br />The processors are identical and that is what matters for my program. The only difference is that my program is running on Windows in multithreaded mode versus single threaded mode on Ubuntu. The figures for single threaded mode on Windows are literally twice
 the ones I provided for the multithreaded version, with the exception of the one for the test of M21701, which is run using a single thread.<br /><br />As for Ubuntu having a potential driver advantage, because it is running in Virtual PC, it has to interface with emulated hardware while Windows can interact directly with the hardware and also has the latest drivers from Intel, Nvidia, Creative etcetera. If
 the drivers on Windows were suboptimal, I would expect that to directly affect any OS running under Virtual PC.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/175e35eee879492ba3cf9dfa00c054b6#175e35eee879492ba3cf9dfa00c054b6</link>
		<pubDate>Sun, 02 Mar 2008 01:03:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/175e35eee879492ba3cf9dfa00c054b6#175e35eee879492ba3cf9dfa00c054b6</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>Have you tried running a binary for Windows compiled with GCC?<br /><br />Or the VC built version under WINE under Ubuntu?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e0db40142cdc40caa7879dfa00c05543#e0db40142cdc40caa7879dfa00c05543</link>
		<pubDate>Sun, 02 Mar 2008 01:17:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e0db40142cdc40caa7879dfa00c05543#e0db40142cdc40caa7879dfa00c05543</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">W3bbo wrote:</div>
<div class="quoteBody">&#65279;Have you tried running a binary for Windows compiled with GCC?<br /><br />Or the VC built version under WINE under Ubuntu?<br /></div>
</blockquote>
<br /><br />No. How would I go about doing that?<br /><br />By the way, I reran the tests on Windows in single threaded mode with the processor affinity set so that the process would not jump from core to core and started my program from Visual Studio without debugging. The numbers after doing that were 5 seconds for
 0 - 2281, 17 seconds for 0 - 3217, 12 seconds for 2281 - 3217 and 20 seconds for M21701. These numbers look even worse for Windows (the previous ones were slanted in Windows' favor as they were taken with the multithreaded version), but it is an apples to
 apples comparison.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/46469fe417db403a9b739dfa00c05584#46469fe417db403a9b739dfa00c05584</link>
		<pubDate>Sun, 02 Mar 2008 01:22:12 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/46469fe417db403a9b739dfa00c05584#46469fe417db403a9b739dfa00c05584</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>I see that you are linking to GMP in Linux, what math library are you using in Windows? Are you using a port of GMP for Windows? If so, which port? Where did you get it from and how was it compiled?<br /><br />Since computing Mersenne Primes with the Lucas Lehmer test is pretty FFT/iFFT intensive the quality of whatever math library you are using is key.<br /><br />Seeing as how Prime95 for windows and GLucas for linux/mac both seem to run about the same speed, (granted they both use highly optimized assembly for the FFTs) I highly doubt that Windows is making things slower. (See
<a href="http://www.mersenne.org/">http://www.mersenne.org/</a>)<br /><br />You claim to be comparing apples to apples, but I highly doubt it.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/ccfa6fc8966d42eaa34a9dfa00c055d3#ccfa6fc8966d42eaa34a9dfa00c055d3</link>
		<pubDate>Sun, 02 Mar 2008 01:53:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/ccfa6fc8966d42eaa34a9dfa00c055d3#ccfa6fc8966d42eaa34a9dfa00c055d3</guid>
		<dc:creator>Antitorgo</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Antitorgo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Antitorgo wrote:</div>
<div class="quoteBody">&#65279;
<p>I see that you are linking to GMP in Linux, what math library are you using in Windows? Are you using a port of GMP for Windows? If so, which port? Where did you get it from and how was it compiled?<br /><br />Since computing Mersenne Primes with the Lucas Lehmer test is pretty FFT/iFFT intensive the quality of whatever math library you are using is key.<br /><br />Seeing as how Prime95 for windows and GLucas for linux/mac both seem to run about the same speed, (granted they both use highly optimized assembly for the FFTs) I highly doubt that Windows is making things slower. (See
<a href="http://www.mersenne.org/">http://www.mersenne.org/</a>)<br /><br />You claim to be comparing apples to apples, but I highly doubt it.</p>
</div>
</blockquote>
<br /><br />I am using GMP on windows as well:<br /><br /><a href="http://fp.gladman.plus.com/computing/gmp4win.htm">http://fp.gladman.plus.com/computing/gmp4win.htm</a><br /><br />I simply had to apply the patch, follow the instructions in the README, compile lib_gmp_gc in Visual Studio, add it to my solution and put the path to the build.vc8 directory as an additional includes directory in my project's property pages. I also applied
 all of the optimization flags that I applied to my project to the lib_gmp_gc project.<br /><br />By the way, I have been to mersenne.org in the past and I have a thread discussing this on mersenneforum.org:<br /><br /><a href="http://www.mersenneforum.org/showthread.php?p=127550">http://www.mersenneforum.org/showthread.php?p=127550</a><br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/2f3da1c77e004a6a835a9dfa00c0561a#2f3da1c77e004a6a835a9dfa00c0561a</link>
		<pubDate>Sun, 02 Mar 2008 02:14:59 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/2f3da1c77e004a6a835a9dfa00c0561a#2f3da1c77e004a6a835a9dfa00c0561a</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/dd1507268e434c1bb8ae9dfa00c05658#dd1507268e434c1bb8ae9dfa00c05658</link>
		<pubDate>Sun, 02 Mar 2008 02:16:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/dd1507268e434c1bb8ae9dfa00c05658#dd1507268e434c1bb8ae9dfa00c05658</guid>
		<dc:creator>TimP</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TimP/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</div>
</blockquote>
<br /><br />Optimizations are good... but I'd never expect a 50% gain in performance with them.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/2aa186755f0946e1830e9dfa00c056d6#2aa186755f0946e1830e9dfa00c056d6</link>
		<pubDate>Sun, 02 Mar 2008 02:18:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/2aa186755f0946e1830e9dfa00c056d6#2aa186755f0946e1830e9dfa00c056d6</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</div>
</blockquote>
<br /><br />It would be difficult to compile my program with no optimizations in GCC, as GMP's make script automatically compiles GMP with the most optimal compiler flags available while Visual Studio will recompile GMP as a debug build if I was to try to compile my program
 in debug mode. That prevents a fair comparsion with optimizations disabled.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b3b20a5e8e3d48329ed59dfa00c05715#b3b20a5e8e3d48329ed59dfa00c05715</link>
		<pubDate>Sun, 02 Mar 2008 02:21:34 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b3b20a5e8e3d48329ed59dfa00c05715#b3b20a5e8e3d48329ed59dfa00c05715</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">W3bbo wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</i></td>
</tr>
</tbody>
</table>
</blockquote>
<p><br /><br />Optimizations are good... but I'd never expect a 50% gain in performance with them.<br /></p>
</div>
</blockquote>
<br /><br />I would assume so too, but it's worth ruling out.<br /><br />I'm slightly confused by the invocation of gcc.
<p></p>
<p>gcc -m32 -O2 -fomit-frame-pointer -mtune=k8 -march=k8 mersenne.c /usr/local/lib/gmp.so<br /><br />Adding the path to gmp.so, in particular. If my understanding of the gcc documentation is accurate, it will regard gmp.so as an &quot;in file&quot;, which would seem to imply (if gcc is not complaining) that gmp.so is being statically linked with your executable. You
 can test this by running <font face="Courier New">ldd yourbinary</font><font face="Verdana">. If you don't see gmp.so in the output, you're statically linking. I'm not well versed on VC&#43;&#43;, so I don't know if your VC&#43;&#43; build is performing static linking or
 how you would check on Windows. Can anyone chime in?<br /><br />Back to the point at hand though, if this was the case you should have a fixed delay since dynamic linking resolution is done at invocation and the runtime differences would always be different by a roughly fixed amount.</font></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/a01db937d7a443bc87fb9dfa00c05763#a01db937d7a443bc87fb9dfa00c05763</link>
		<pubDate>Sun, 02 Mar 2008 02:26:25 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/a01db937d7a443bc87fb9dfa00c05763#a01db937d7a443bc87fb9dfa00c05763</guid>
		<dc:creator>TimP</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TimP/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">W3bbo wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Optimizations are good... but I'd never expect a 50% gain in performance with them.</div>
</blockquote>
<br /><br />The gain in performance is far greater than 50% depending on the test case, as when I ran the original tests, I had the multithreaded code path enabled in Visual Studio. I reran them with the single threaded code path and posted the new numbers not that long
 ago.<br /><br />I will restate them with gains in performance computated:<br /><br />It takes 1 second to test M0 through M2281 on Ubuntu and 5 seconds on Windows, making Ubuntu 400% faster.<br />It takes 5 seconds to test M0 through M3217 on Ubuntu and 12 seconds on Windows, making Ubuntu 140% faster.<br />It takes 6 seconds to test M2281 through M3217 on Ubuntu and 17 seconds on Windows, making Ubuntu 183% faster.<br />It takes 7 seconds to test M21701 on Ubuntu and 20 seconds on Windows, making Ubuntu 186% faster.<br /><br /><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>W3bbo wrote:</strong>
<hr size="1">
<i>&#65279; </i>
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</i></td>
</tr>
</tbody>
</table>
</blockquote>
<p><i><br /><br />Optimizations are good... but I'd never expect a 50% gain in performance with them.<br /></i></p>
</td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />I would assume so too, but it's worth ruling out.<br /><br />I'm slightly confused by the invocation of gcc.
<p>gcc -m32 -O2 -fomit-frame-pointer -mtune=k8 -march=k8 mersenne.c /usr/local/lib/gmp.so<br /><br />Adding the path to gmp.so, in particular. If my understanding of the gcc documentation is accurate, it will regard gmp.so as an &quot;in file&quot;, which would seem to imply (if gcc is not complaining) that gmp.so is being statically linked with your executable. You
 can test this by running <font face="Courier New">ldd yourbinary</font><font face="Verdana">. If you don't see gmp.so in the output, you're statically linking. I'm not well versed on VC&#43;&#43;, so I don't know if your VC&#43;&#43; build is performing static linking or
 how you would check on Windows. Can anyone chime in?<br /><br />Back to the point at hand though, if this was the case you should have a fixed delay since dynamic linking resolution is done at invocation and the runtime differences would always be different by a roughly fixed amount.</font></p>
</div>
</blockquote>
<br /><br />Here is the output:<br /><br />richard@richard-desktop:~$ ldd ./a.out<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linux-gate.so.1 =&gt;&nbsp; (0xffffe000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libgmp.so.3 =&gt; /usr/local/lib/libgmp.so.3 (0xb7f7a000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libc.so.6 =&gt; /lib/tls/i686/cmov/libc.so.6 (0xb7e40000)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lib/ld-linux.so.2 (0xb7fb4000)<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b0e6b58ec0f6452d84b29dfa00c057c4#b0e6b58ec0f6452d84b29dfa00c057c4</link>
		<pubDate>Sun, 02 Mar 2008 02:39:36 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b0e6b58ec0f6452d84b29dfa00c057c4#b0e6b58ec0f6452d84b29dfa00c057c4</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;
<p>So it is indeed doing dynamic linking. Maybe passing shared objects to gcc implicitly tells it to link them dynamically, but I've never seen it done before (I usually see -l&lt;lib&gt;).<br /><br />Since the running time seems to grow with the size of the input, my only guess is that threading is being (ab)used in a way that pthreads handle more gracefully than Windows threading (assuming pthreads-win32 is a wrapper for Windows threads). I would attempt
 to run to core calculations of the algorithm without any threading involved and compare the numbers.</p>
</div>
</blockquote>
<br /><br />Those numbers are without any threading involved. The original ones for WIndows were with threading involved.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/69c002907e2a4e4f9a0c9dfa00c0584b#69c002907e2a4e4f9a0c9dfa00c0584b</link>
		<pubDate>Sun, 02 Mar 2008 02:40:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/69c002907e2a4e4f9a0c9dfa00c0584b#69c002907e2a4e4f9a0c9dfa00c0584b</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>So it is indeed doing dynamic linking. Maybe passing shared objects to gcc implicitly tells it to link them dynamically, but I've never seen it done before (I usually see -l&lt;lib&gt;).<br /><br />Since the running time seems to grow with the size of the input, my only guess is that threading is being (ab)used in a way that pthreads handle more gracefully than Windows threading (assuming pthreads-win32 is a wrapper for Windows threads). I would attempt
 to run to core calculations of the algorithm without any threading involved and compare the numbers. I'm not sure what you're using to do your timing, but there is a time program standard on Linux that you can use that will give you a more detailed breakdown.<br /><br />time ./a.out</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/aca54895d2ec4dafb0769dfa00c05807#aca54895d2ec4dafb0769dfa00c05807</link>
		<pubDate>Sun, 02 Mar 2008 02:40:47 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/aca54895d2ec4dafb0769dfa00c05807#aca54895d2ec4dafb0769dfa00c05807</guid>
		<dc:creator>TimP</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TimP/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;
<p>So it is indeed doing dynamic linking. Maybe passing shared objects to gcc implicitly tells it to link them dynamically, but I've never seen it done before (I usually see -l&lt;lib&gt;).<br /><br />Since the running time seems to grow with the size of the input, my only guess is that threading is being (ab)used in a way that pthreads handle more gracefully than Windows threading (assuming pthreads-win32 is a wrapper for Windows threads). I would attempt
 to run to core calculations of the algorithm without any threading involved and compare the numbers. I'm not sure what you're using to do your timing, but there is a time program standard on Linux that you can use.<br /><br />time ./a.out</p>
</div>
</blockquote>
<br /><br />I see you edited your post. Anyway, I am using time.h to do timing. I reran my program using Linux's time program and here is the output:<br /><br />richard@richard-desktop:~$ time ./a.out 0 2281<br />M2 is prime<br />M3 is prime<br />M5 is prime<br />M7 is prime<br />M13 is prime<br />M17 is prime<br />M19 is prime<br />M31 is prime<br />M61 is prime<br />M89 is prime<br />M107 is prime<br />M127 is prime<br />M521 is prime<br />M607 is prime<br />M1279 is prime<br />M2203 is prime<br />M2281 is prime<br /><br />17 prime numbers were found. It took 1.00 seconds<br /><br />real&nbsp;&nbsp;&nbsp; 0m1.676s<br />user&nbsp;&nbsp;&nbsp; 0m1.652s<br />sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.008s<br />richard@richard-desktop:~$ time ./a.out 0 3217<br />M2 is prime<br />M3 is prime<br />M5 is prime<br />M7 is prime<br />M13 is prime<br />M17 is prime<br />M19 is prime<br />M31 is prime<br />M61 is prime<br />M89 is prime<br />M107 is prime<br />M127 is prime<br />M521 is prime<br />M607 is prime<br />M1279 is prime<br />M2203 is prime<br />M2281 is prime<br />M3217 is prime<br /><br />18 prime numbers were found. It took 5.00 seconds<br /><br />real&nbsp;&nbsp;&nbsp; 0m5.284s<br />user&nbsp;&nbsp;&nbsp; 0m5.228s<br />sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.008s<br />richard@richard-desktop:~$ time ./a.out 2281 3217<br />M2281 is prime<br />M3217 is prime<br /><br />2 prime numbers were found. It took 4.00 seconds<br /><br />real&nbsp;&nbsp;&nbsp; 0m3.684s<br />user&nbsp;&nbsp;&nbsp; 0m3.620s<br />sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.016s<br />richard@richard-desktop:~$ time ./a.out 21701<br />M21701 is prime<br /><br />1 prime numbers were found. It took 6.00 seconds<br /><br />real&nbsp;&nbsp;&nbsp; 0m6.612s<br />user&nbsp;&nbsp;&nbsp; 0m6.204s<br />sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.020s<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/746e1d7ec12d4598a6869dfa00c058a3#746e1d7ec12d4598a6869dfa00c058a3</link>
		<pubDate>Sun, 02 Mar 2008 02:45:12 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/746e1d7ec12d4598a6869dfa00c058a3#746e1d7ec12d4598a6869dfa00c058a3</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;
<p>So it is indeed doing dynamic linking. Maybe passing shared objects to gcc implicitly tells it to link them dynamically, but I've never seen it done before (I usually see -l&lt;lib&gt;).<br /><br />Since the running time seems to grow with the size of the input, my only guess is that threading is being (ab)used in a way that pthreads handle more gracefully than Windows threading (assuming pthreads-win32 is a wrapper for Windows threads). I would attempt
 to run to core calculations of the algorithm without any threading involved and compare the numbers.</p>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Those numbers are without any threading involved. The original ones for WIndows were with threading involved.<br /></div>
</blockquote>
<br /><br />Is the processor multicore? (I didn't see it mentioned in the OP) If it isn't, threading code is just overhead and performance will be degraded on your Windows test.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/148fb30c02474765964d9dfa00c058ed#148fb30c02474765964d9dfa00c058ed</link>
		<pubDate>Sun, 02 Mar 2008 02:57:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/148fb30c02474765964d9dfa00c058ed#148fb30c02474765964d9dfa00c058ed</guid>
		<dc:creator>TimP</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TimP/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;
<p>So it is indeed doing dynamic linking. Maybe passing shared objects to gcc implicitly tells it to link them dynamically, but I've never seen it done before (I usually see -l&lt;lib&gt;).<br /><br />Since the running time seems to grow with the size of the input, my only guess is that threading is being (ab)used in a way that pthreads handle more gracefully than Windows threading (assuming pthreads-win32 is a wrapper for Windows threads). I would attempt
 to run to core calculations of the algorithm without any threading involved and compare the numbers.</p>
</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Those numbers are without any threading involved. The original ones for WIndows were with threading involved.<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Is the processor multicore? (I didn't see it mentioned in the OP) If it isn't, threading code is just overhead and performance will be degraded on your Windows test.</div>
</blockquote>
<br /><br />It is an Intel Core 2 Duo E6300 with 4GB of RAM (4x1GB) on an Asus P5K Deluxe motherboard.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/7c7cb2b1bd3f4e6c86c39dfa00c05939#7c7cb2b1bd3f4e6c86c39dfa00c05939</link>
		<pubDate>Sun, 02 Mar 2008 03:21:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/7c7cb2b1bd3f4e6c86c39dfa00c05939#7c7cb2b1bd3f4e6c86c39dfa00c05939</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>When I try to find this kind of thing, I try to eliminate as much as possible, then add stuff back until I find the issue.&nbsp; Try running test on native OS in both cases w/o VM.&nbsp; Also, verify your timer code is same in both cases.&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/152275f048a6469aaf769dfa00c059c7#152275f048a6469aaf769dfa00c059c7</link>
		<pubDate>Sun, 02 Mar 2008 03:49:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/152275f048a6469aaf769dfa00c059c7#152275f048a6469aaf769dfa00c059c7</guid>
		<dc:creator>William Stacey</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/staceyw/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">staceyw wrote:</div>
<div class="quoteBody">&#65279;When I try to find this kind of thing, I try to eliminate as much as possible, then add stuff back until I find the issue.&nbsp; Try running test on native OS in both cases w/o VM.&nbsp; Also, verify your timer code is same in both cases.&nbsp;</div>
</blockquote>
<br /><br />I compiled a version of my program that had all of the multithreading code stripped by hand. It made no difference.<br /><br />I am not quite sure what you mean by &quot;Try running test on native OS in both cases w/o VM.&quot;<br /><br />Also, the timer code is identical on both Ubuntu and Windows.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e937914ba1264b449a639dfa00c05a07#e937914ba1264b449a639dfa00c05a07</link>
		<pubDate>Sun, 02 Mar 2008 04:04:13 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e937914ba1264b449a639dfa00c05a07#e937914ba1264b449a639dfa00c05a07</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p></p>
<blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;<br />I am not quite sure what you mean by &quot;Try running test on native OS in both cases w/o VM.&quot;<br /></div>
</blockquote>
<br /><br />Run it without a virtual machine. The Ubuntu 6.10 disc can be used as a LiveCD. In this case though, the performance issues seem to be with the host operating system, so if anything running Linux on bare metal would only skew the numbers more.
<p></p>
<p>If you were having problems with the Linux side I would offer my help, but unfortunately I don't have much experience debugging or tuning&nbsp;unmanaged&nbsp;applications on Windows. <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-6.gif' alt='Sad' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/da363820b9db48e0940a9dfa00c05a49#da363820b9db48e0940a9dfa00c05a49</link>
		<pubDate>Sun, 02 Mar 2008 04:10:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/da363820b9db48e0940a9dfa00c05a49#da363820b9db48e0940a9dfa00c05a49</guid>
		<dc:creator>TimP</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TimP/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">TimP wrote:</div>
<div class="quoteBody">&#65279;
<p></p>
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;<br />I am not quite sure what you mean by &quot;Try running test on native OS in both cases w/o VM.&quot;<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Run it without a virtual machine. The Ubuntu 6.10 disc can be used as a LiveCD. In this case though, the performance issues seem to be with the host operating system, so if anything running Linux on bare metal would only skew the numbers more.
<p></p>
<p>If you were having problems with the Linux side I would offer my help, but unfortunately I don't have much experience debugging or tuning&nbsp;unmanaged&nbsp;applications on Windows.
<img src="/emoticons/emotion-6.gif" border="0"></p>
</div>
</blockquote>
<br /><br />The LiveCD is an ISO that I use in a virtual optical drive. If I wanted to run it, I would have to burn it, but as you said, running Linux directly would only skew the numbers more, although I imagine that it would enable me to run my program in multithreaded
 mode, which would be really cool, especially on 64bit Linux where I would expect computation speeds to increase by a factor of 4 simply from the move to 64bit processing.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/6f544e0387204b14b8ab9dfa00c05a96#6f544e0387204b14b8ab9dfa00c05a96</link>
		<pubDate>Sun, 02 Mar 2008 04:19:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/6f544e0387204b14b8ab9dfa00c05a96#6f544e0387204b14b8ab9dfa00c05a96</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>I've read about similar sorts of perf issues with various STL containers (C&#43;&#43;) and all of the bounds-checking that occurs by default using the new compilers.<br /><br />I'd expect there's a similar thing at work here (with your C code), so research that.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e8e653a3621e4e209cd09dfa00c05b13#e8e653a3621e4e209cd09dfa00c05b13</link>
		<pubDate>Sun, 02 Mar 2008 04:37:59 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e8e653a3621e4e209cd09dfa00c05b13#e8e653a3621e4e209cd09dfa00c05b13</guid>
		<dc:creator>RichardRudek</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/RichardRudek/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">RichardRudek wrote:</div>
<div class="quoteBody">&#65279;I've read about similar sorts of perf issues with various STL containers (C&#43;&#43;) and all of the bounds-checking that occurs by default using the new compilers.<br /><br />I'd expect there's a similar thing at work here (with your C code), so research that.<br /></div>
</blockquote>
<br /><br />Bounds checking? C is not supposed to have bounds checking. That is a Java feature.<br /><br />Bounds checking could be related is related to the Buffer Security Check, which I have disabled. I am not sure if there are any other features that Microsoft put into its compiler that would do this sort of checking. Is anyone from the Visual Studio team reading
 this thread and do you have anything to say about any of the things mentioned in the thread?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/1d50e7f9b3854bb8a33b9dfa00c05b58#1d50e7f9b3854bb8a33b9dfa00c05b58</link>
		<pubDate>Sun, 02 Mar 2008 05:00:24 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/1d50e7f9b3854bb8a33b9dfa00c05b58#1d50e7f9b3854bb8a33b9dfa00c05b58</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>I really don't think it is an OS issue (I could almost guarantee it). My guess is that it is a difference in the compilers. I'm not sure how much if any code was changed to port GMP to Win32 but there could definitely be something going on there.<br /><br />Any chance you could post the code somewhere for people to take a look at and see if they are seeing the same thing you are?<br /><br />As far as anyone from the Visual Studio team responding... I'm not sure if anyone from those teams visits Channel 9. So I wouldn't count on anyone from there replying to this thread. (It is possible, just not likely IMO)</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/5a700e1cc9514b5ca2df9dfa00c05b9c#5a700e1cc9514b5ca2df9dfa00c05b9c</link>
		<pubDate>Sun, 02 Mar 2008 05:37:13 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/5a700e1cc9514b5ca2df9dfa00c05b9c#5a700e1cc9514b5ca2df9dfa00c05b9c</guid>
		<dc:creator>Antitorgo</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Antitorgo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;<br />&nbsp;I also applied all of the optimization flags that I applied to my project to the
<b>lib_gmp_gc</b> project.</div>
</blockquote>
<br /><br />I've never used this library. So I go and download the bits, and then realise what you said above, which I embolded.<br /><br />The whole point of this library is that key parts of it are compiled using hand optimised assembler. Yet you've elected to compile the Windows library using the Generic C version. Why ?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/4e59343ec2a3459886519dfa00c05c18#4e59343ec2a3459886519dfa00c05c18</link>
		<pubDate>Sun, 02 Mar 2008 12:35:27 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/4e59343ec2a3459886519dfa00c05c18#4e59343ec2a3459886519dfa00c05c18</guid>
		<dc:creator>RichardRudek</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/RichardRudek/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>maybe the problem is in widows port of gmp?<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/3b59ec15c564401aa4ca9dfa00c05c54#3b59ec15c564401aa4ca9dfa00c05c54</link>
		<pubDate>Sun, 02 Mar 2008 13:34:34 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/3b59ec15c564401aa4ca9dfa00c05c54#3b59ec15c564401aa4ca9dfa00c05c54</guid>
		<dc:creator>Ion Todirel</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Ion Todirel/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">RichardRudek wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;<br />&nbsp;I also applied all of the optimization flags that I applied to my project to the
<b>lib_gmp_gc</b> project.</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />I've never used this library. So I go and download the bits, and then realise what you said above, which I embolded.<br /><br />The whole point of this library is that key parts of it are compiled using hand optimised assembler. Yet you've elected to compile the Windows library using the Generic C version. Why ?<br /></div>
</blockquote>
<br /><br />Good point. GMP on Ubuntu compiled optimized for the k8 architecture, so it probably has the advantage of optimized assembly.<br /><br />I recompiled my program with P4 optimized assembly and there was quite a speed increase.<br /><br />Here are the new numbers. Note that I updated the Ubuntu numbers with the ones from the tests I did for TimP, as they were slightly better than the previous ones and I was using the best that I could get for windows, so it was only fair:<br /><br />It takes 1 second to test M0 through M2281 on Ubuntu and 2 seconds on Windows, making Ubuntu 100% faster.<br />It takes 4 seconds to test M2281 through M3217 on Ubuntu and 3 seconds on Windows, making Ubuntu 33% slower.<br />It takes 5 seconds to test M0 through M3217 on Ubuntu and 5 seconds on Windows, making it a tie.<br />It takes 6 seconds to test M21701 on Ubuntu and 6 seconds on Windows, making it a tie.<br /><br />This solves the mystery. This also demonstrates that human compiled code can be far better optimized than machine compiled code. Thankyou everyone for your help.<br /><br />By the way, I made a mistake when posting the original Ubuntu numbers. The 5 second figure was for M2281 through M3217 and the 6 second figure was for M0 through M3217. It is not a major issue, but the math does not add up when you consider the fact that I
 simply split M0 to M3217 into two separate test runs for the other tests.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/ed2173a786ad4d498a299dfa00c05ca0#ed2173a786ad4d498a299dfa00c05ca0</link>
		<pubDate>Sun, 02 Mar 2008 13:44:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/ed2173a786ad4d498a299dfa00c05ca0#ed2173a786ad4d498a299dfa00c05ca0</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;<br />It takes 1 second to test M0 through M2281 on Ubuntu and 2 seconds on Windows, making Ubuntu 100% faster.<br /></div>
</blockquote>
<br /><br />From what I remember of your original numbers, you're getting <em>huge</em> rounding errors here. The 1sec reported by
<em>time</em> on linux was actually 1.6seconds. Try calculating this with more decimal points and you'll get wildly different ratios.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/f226c0b97f8f4f488c259dfa00c05d1a#f226c0b97f8f4f488c259dfa00c05d1a</link>
		<pubDate>Sun, 02 Mar 2008 14:07:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/f226c0b97f8f4f488c259dfa00c05d1a#f226c0b97f8f4f488c259dfa00c05d1a</guid>
		<dc:creator>Yggdrasil</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Yggdrasil/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Yggdrasil wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;<br />It takes 1 second to test M0 through M2281 on Ubuntu and 2 seconds on Windows, making Ubuntu 100% faster.<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />From what I remember of your original numbers, you're getting <em>huge</em> rounding errors here. The 1sec reported by
<em>time</em> on linux was actually 1.6seconds. Try calculating this with more decimal points and you'll get wildly different ratios.<br /></div>
</blockquote>
<br /><br />I cannot calculate this with more decimal points. time.h only reports seconds.<br /><br />The case M0 through M3217 includes M0 through M2281 and M2281 through M3217 and is the same for both Ubuntu and Windows, so as far as I am concerned, performance on Windows and performance on Ubuntu are identical.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/fffe88e897f24952940c9dfa00c05d5e#fffe88e897f24952940c9dfa00c05d5e</link>
		<pubDate>Sun, 02 Mar 2008 14:51:33 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/fffe88e897f24952940c9dfa00c05d5e#fffe88e897f24952940c9dfa00c05d5e</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;I cannot calculate this with more decimal points. time.h only reports seconds.</div>
</blockquote>
<br /><br /><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody"><br />richard@richard-desktop:~$ time ./a.out 0 2281<br />.<br />.<br />.<br />17 prime numbers were found. It took 1.00 seconds<br /><strong>real&nbsp;&nbsp;&nbsp; 0m1.676s<br /></strong>user&nbsp;&nbsp;&nbsp; 0m1.652s<br />sys&nbsp;&nbsp;&nbsp;&nbsp; 0m0.008s<br /></div>
</blockquote>
<br /><br />Isn't this good enough?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/fd2ab75d7d00438b94d69dfa00c05dd8#fd2ab75d7d00438b94d69dfa00c05dd8</link>
		<pubDate>Sun, 02 Mar 2008 15:34:04 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/fd2ab75d7d00438b94d69dfa00c05dd8#fd2ab75d7d00438b94d69dfa00c05dd8</guid>
		<dc:creator>Yggdrasil</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Yggdrasil/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>Not when you consider the fact that there is no analogous measurement method available on Windows.<br /><br />I would have to write a time program myself and I have other things to do.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/7704393f5d044034a11a9dfa00c05e18#7704393f5d044034a11a9dfa00c05e18</link>
		<pubDate>Sun, 02 Mar 2008 16:13:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/7704393f5d044034a11a9dfa00c05e18#7704393f5d044034a11a9dfa00c05e18</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p></p>
<blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;Not when you consider the fact that there is no analogous measurement method avaliable on Windows..<br /></div>
</blockquote>
<br /><br />You didn't look very hard, did you? <br /><br /><br />ptime 1.0 for Win32, Freeware - <a href="http://www.pc-tools.net/">http://www.pc-tools.net/</a><br />Copyright(C) 2002, Jem Berkes &lt;<a href="mailto:jberkes@pc-tools.net">jberkes@pc-tools.net</a>&gt;
<p></p>
<p>Syntax: ptime command [arguments ...]</p>
<p>ptime will run the specified command and measure the execution time (run time) in seconds, accurate to 5 millisecond or better. It is an automatic process timer, or program timer.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/d00f99b84490473c9d6a9dfa00c05e96#d00f99b84490473c9d6a9dfa00c05e96</link>
		<pubDate>Sun, 02 Mar 2008 16:16:21 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/d00f99b84490473c9d6a9dfa00c05e96#d00f99b84490473c9d6a9dfa00c05e96</guid>
		<dc:creator>Yggdrasil</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Yggdrasil/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">W3bbo wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>TimP wrote:</strong>
<hr size="1">
<i>&#65279;Perhaps gcc is performing optimizations that VC&#43;&#43; is not. Try compiling them both with no optimizations and test the run times. If they're equivalent, then gcc is optimizing more aggressively, otherwise the culprit is elsewhere.</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Optimizations are good... but I'd never expect a 50% gain in performance with them.<br /></div>
</blockquote>
<br /><br />Depends on the program. Some programs simply can't be optimised, others can get a 90% improvement using cheap optimisations. In general debug optimisations give a 7% increase in speed but take up more memory, semi-release optimisations get an about 20% improvement
 and a full-optimisation for final release is about 25-40% speed-up.<br /><br /><br /><br /><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;<br />Bounds checking? C is not supposed to have bounds checking. That is a Java feature.<br /><br />Bounds checking could be related is related to the Buffer Security Check, which I have disabled. I am not sure if there are any other features that Microsoft put into its compiler that would do this sort of checking. Is anyone from the Visual Studio team reading
 this thread and do you have anything to say about any of the things mentioned in the thread?<br /></div>
</blockquote>
<br /><br />Bounds checking in C is hard, but possible, and actually happens in lots of modern C compilers (including GCC and VC&#43;&#43;). With static arrays it's easy:<br /><br />int c[100];<br />for(int i=0;i&lt;<font color="#ff0000">=</font>100;i&#43;&#43;){<br /><font color="#ff0000">&nbsp; if(i &gt; 100) #error // inserted by the compiler.</font><br />&nbsp; c[i] = i;<br />}<br /><br />Will error when you build the flow graph. With dynamically allocated memory it's more expensive:<br /><br />int * myArray = calloc(100, sizeof(int));<br />for(int i=0;i&lt;=100;i&#43;&#43;){<br />&nbsp; myArray[i] = i;<br />}<br /><br /><br />int * myArray = calloc(100, sizeof(int));<br />for(int i=0;i&lt;=100;i&#43;&#43;){<br /><font color="#ff0000">&nbsp; int __cptr = (int)myArray &#43; sizeof(int) * i;<br />&nbsp; if(malloc_index(__cptr) == -1 || malloc_index(myArray) != malloc_index(__cptr)) #error
<br />&nbsp; *__cptr = i;</font><br />}<br /><br />where malloc_index looks through the malloc table (<i>O</i>(log n)) and returns the index in the table that corresponds to the pointer.<br /><br /><br /><br /><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;Not when you consider the fact that there is no analogous measurement method available on Windows.<br /><br />I would have to write a time program myself and I have other things to do.<br /></div>
</blockquote>
<br /><br />You should do the test many times:<br /><br />float f;<br />int i, time;<br /><br />setup_low_resolution_timer();<br />for(i=0;i&lt;1000;i&#43;&#43;){<br />&nbsp; do_function();<br />}<br />time = stop_low_resolution_timer();<br /><br />f = ((float)time / 1000);<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b4a2b78a1a22482d85b69dfa00c05f44#b4a2b78a1a22482d85b69dfa00c05f44</link>
		<pubDate>Sun, 02 Mar 2008 16:36:34 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/b4a2b78a1a22482d85b69dfa00c05f44#b4a2b78a1a22482d85b69dfa00c05f44</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;<br />Bounds checking? C is not supposed to have bounds checking. That is a Java feature.<br /><br />Bounds checking could be related is related to the Buffer Security Check, which I have disabled. I am not sure if there are any other features that Microsoft put into its compiler that would do this sort of checking. Is anyone from the Visual Studio team reading
 this thread and do you have anything to say about any of the things mentioned in the thread?<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Bounds checking in C is hard, but possible, and actually happens in lots of modern C compilers (including GCC and VC&#43;&#43;). With static arrays it's easy:<br /><br />int c[100];<br />for(int i=0;i&lt;<font color="#ff0000">=</font>100;i&#43;&#43;){<br /><font color="#ff0000">&nbsp; if(i &gt; 100) #error // inserted by the compiler.</font><br />&nbsp; c[i] = i;<br />}<br /><br />Will error when you build the flow graph. With dynamically allocated memory it's more expensive:<br /><br />int * myArray = calloc(100, sizeof(int));<br />for(int i=0;i&lt;=100;i&#43;&#43;){<br />&nbsp; myArray[i] = i;<br />}<br /><br /><br />int * myArray = calloc(100, sizeof(int));<br />for(int i=0;i&lt;=100;i&#43;&#43;){<br /><font color="#ff0000">&nbsp; int __cptr = (int)myArray &#43; sizeof(int) * i;<br />&nbsp; if(malloc_index(__cptr) == -1 || malloc_index(myArray) != malloc_index(__cptr)) #error
<br />&nbsp; *__cptr = i;</font><br />}<br /><br />where malloc_index looks through the malloc table (<i>O</i>(log n)) and returns the index in the table that corresponds to the pointer.</div>
</blockquote>
<br /><br />I do not want the compiler to try to second guess whether or not I have adequetely ensured that my loop bounds are always in range. Is there any way to disable that feature in GCC (3.4.6 and up) and Visual Studio 2008 Professional?<br /><br /><blockquote>
<div class="quoteAuthor">evildictaitor wrote:</div>
<div class="quoteBody">&#65279;<br /><blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Shining Arcanine wrote:</strong>
<hr size="1">
<i>&#65279;Not when you consider the fact that there is no analogous measurement method available on Windows.<br /><br />I would have to write a time program myself and I have other things to do.<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />You should do the test many times:<br /><br />float f;<br />int i, time;<br /><br />setup_low_resolution_timer();<br />for(i=0;i&lt;1000;i&#43;&#43;){<br />&nbsp; do_function();<br />}<br />time = stop_low_resolution_timer();<br /><br />f = ((float)time / 1000);</div>
</blockquote>
<br /><br />That is an option that I will probably use in the future when tweaking my program to get more performance, although for now, I am considering the case to be closed. I believe the minor deviations in the figures are the result of the use of different optimized
 assembly routines on Windows and Ubuntu, as GMP has optimized assembly for many different platforms (although not as many as I would like, as that there is no optimized assembly for the Core 2 Duo) and Brian Gladman's Visual Studio patch for GMP only provides
 project files for a few of them.<br /><br />Since GMP's make file system was compiling it to be optimized for the K8 microarchitecture, I assume that it used the K7 optimized assembly, which is separate from the P4 optimized assembly that I am using in Visual Studio. The Visual Studio patch provides
 no project files for the K7 optimized assembly and the cost of creating them to verify my conjecture far outweighs the potential gains, so further analysis in the context of higher priority things (I have to write a scanner by Tuesday for my C&#43;&#43; class and
 I have to be prepared for two midterms by Thursday) being on my to do list is pointless.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/6b4f1f608061466abd449dfa00c05fa3#6b4f1f608061466abd449dfa00c05fa3</link>
		<pubDate>Sun, 02 Mar 2008 20:48:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/6b4f1f608061466abd449dfa00c05fa3#6b4f1f608061466abd449dfa00c05fa3</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;<br />I do not want the compiler to try to second guess whether or not I have adequetely ensured that my loop bounds are always in range. Is there any way to disable that feature in GCC (3.4.6 and up) and Visual Studio 2008 Professional?<br /></div>
</blockquote>
<br />In VS08 it's called bounds checking and it can be disabled as one of the options for the compiler. In GCC it's off (for C) by default, and better still it can be abstracted away to a compile-time check for most pointers. (<a href="http://www.doc.ic.ac.uk/%7Ephjk/BoundsChecking.html">link</a>)<br /><br /><br /><blockquote>
<div class="quoteAuthor">Shining Arcanine wrote:</div>
<div class="quoteBody">&#65279;That is an option that I will probably use in the future when tweaking my program to get more performance, although for now, I am considering the case to be closed.</div>
</blockquote>
<br /><br />OK, but you need to remember that when working with such small time intervals even things like the scheduler can completely throw your numbers, so doing a time-complexity analysis or just running the tests lots is a better way to see which program is faster,
 but if you're doing it just for fun, a full analysis is somewhat overkill.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e71be0a24bf04b749d709dfa00c06026#e71be0a24bf04b749d709dfa00c06026</link>
		<pubDate>Sun, 02 Mar 2008 21:10:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e71be0a24bf04b749d709dfa00c06026#e71be0a24bf04b749d709dfa00c06026</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>You might try running the windows app in a virtual windows os. It could be something like a virus scanner interfering with the numbers.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/5bc841fe16624bc8a82e9dfa00c060a0#5bc841fe16624bc8a82e9dfa00c060a0</link>
		<pubDate>Mon, 03 Mar 2008 08:26:14 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/5bc841fe16624bc8a82e9dfa00c060a0#5bc841fe16624bc8a82e9dfa00c060a0</guid>
		<dc:creator>longnight</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/longnight/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p>It's worth pointing out that unless you have the VM Additions installed, timing under a virtual OS can be somewhat skewed. And there are no VPC additions for Ubuntu....</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e0d15370276b436f8a3d9dfa00c060db#e0d15370276b436f8a3d9dfa00c060db</link>
		<pubDate>Mon, 03 Mar 2008 10:21:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/e0d15370276b436f8a3d9dfa00c060db#e0d15370276b436f8a3d9dfa00c060db</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">AndyC wrote:</div>
<div class="quoteBody">&#65279;It's worth pointing out that unless you have the VM Additions installed, timing under a virtual OS can be somewhat skewed. And there are no VPC additions for Ubuntu....</div>
</blockquote>
<br /><br />The VPC additions for Red Hat can be coaxed to work under Ubuntu IIRC.<br /><br />Otherwise just use WMWare, Windows 95 and Ubuntu both run better under it in my experience.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/c1e6c55055e24cfd9e319dfa00c06171#c1e6c55055e24cfd9e319dfa00c06171</link>
		<pubDate>Mon, 03 Mar 2008 13:24:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/c1e6c55055e24cfd9e319dfa00c06171#c1e6c55055e24cfd9e319dfa00c06171</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Why does my C program run faster on Linux than on Windows?</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">longnight wrote:</div>
<div class="quoteBody">&#65279;You might try running the windows app in a virtual windows os. It could be something like a virus scanner interfering with the numbers.</div>
</blockquote>
<br /><br />There is no virus scanner on my system.<br /><br /><blockquote>
<div class="quoteAuthor">W3bbo wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>AndyC wrote:</strong>
<hr size="1">
<i>&#65279;It's worth pointing out that unless you have the VM Additions installed, timing under a virtual OS can be somewhat skewed. And there are no VPC additions for Ubuntu....</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />The VPC additions for Red Hat can be coaxed to work under Ubuntu IIRC.<br /><br />Otherwise just use WMWare, Windows 95 and Ubuntu both run better under it in my experience.</div>
</blockquote>
<br /><br />I installed the Additions for Red Hat on my computer, but I believe they need to be installed in the Virtual PC as well. There are no Linux executables I could find on the ISO disk, so I have been having trouble figuring out what I am supposed to do.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/1cd883fb9ede40ab8d059dfa00c061b2#1cd883fb9ede40ab8d059dfa00c061b2</link>
		<pubDate>Mon, 03 Mar 2008 20:02:50 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/261385-Why-does-my-C-program-run-faster-on-Linux-than-on-Windows/1cd883fb9ede40ab8d059dfa00c061b2#1cd883fb9ede40ab8d059dfa00c061b2</guid>
		<dc:creator>Shining Arcanine</dc:creator>
		<slash:comments>39</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Shining Arcanine/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>