Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2694

Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019]

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019]
Date 2021-08-08 12:38 -0700
Organization Compilers Central
Message-ID <21-08-008@comp.compilers> (permalink)
References <21-08-001@comp.compilers> <21-08-003@comp.compilers> <21-08-005@comp.compilers>

Show all headers | View raw


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]

Back to comp.compilers | Previous | NextPrevious in thread | Find similar


Thread

Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019] Paolo Ferraresi <fp.box@alice.it> - 2021-08-05 18:24 +0000
  Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019] George Neuner <gneuner2@comcast.net> - 2021-08-05 22:58 -0400
    Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019] "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2021-08-06 16:14 +0200
      Re: Not normal for the same program to be faster in C# than in C++ [Visual Studio 2019] gah4 <gah4@u.washington.edu> - 2021-08-08 12:38 -0700

csiph-web