Path: csiph.com!xmission!usenet.csail.mit.edu!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: gah4 Newsgroups: comp.compilers Subject: Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019] Date: Sun, 8 Aug 2021 12:38:51 -0700 (PDT) Organization: Compilers Central Lines: 30 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <21-08-008@comp.compilers> References: <21-08-001@comp.compilers> <21-08-003@comp.compilers> <21-08-005@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="14123"; mail-complaints-to="abuse@iecc.com" Keywords: performance, comment Posted-Date: 08 Aug 2021 16:01:54 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <21-08-005@comp.compilers> Xref: csiph.com comp.compilers:2694 On Sunday, August 8, 2021 at 8:14:17 AM UTC-7, Dmitry A. Kazakov wrote: (snip) > P.S. Optimizations is a usual suspect of ruining benchmark measures. Yes. But in this case, one might want to include some optimizations. Note, though, that a good optimizer could optimize out all the loops, as no output depends on them. Some programs I know output the total number of primes found, which stops that from happening. Also, compilers can do some calculations at compile time. I don't expect it for this, but that does ruin some benchmarks. There are stories of complicated benchmarks being done entirely at compile time, except for output of the result. I would have used a j += i loop. Not that multiply is that slow on modern processors, but that it a big part of the loop. One compiler might optimize that one for you. One might store the array as bits (8 bool/byte), the other as bytes. It isn't so obvious which one is faster, but often the 1 bool/byte is faster, until you run out of real memory. How much real memory do you have? And the speed might depend in complicated ways on the memory management system. And note that you aren't comparing languages, but two compilers implementing those languages (which is why it goes here). [In this case, the documentation says they both allocate a byte for each bool but the other stuff is all possible. Also remember C++ is a traditional compiler, while C# is bytecode and JIT. -John]