Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. C# vs. C++ performance [modified] (Contest)

C# vs. C++ performance [modified] (Contest)

Scheduled Pinned Locked Moved The Lounge
csharpc++htmlcss
60 Posts 18 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Super Lloyd

    if it is so obvious there is no need to add anything ;P although I could comment that I do have no clue about what is the diference between the gcc compiler and an optimized compiler ;P

    J Offline
    J Offline
    Jeremy Falcon
    wrote on last edited by
    #37

    Super Lloyd wrote:

    if it is so obvious there is no need to add anything

    It's obvious to us; it's apparently not obvious to you. :-D

    Jeremy Falcon

    1 Reply Last reply
    0
    • S Super Lloyd

      Well, previous post have shown the speed superiority of C++ already. And the slowness of GCC as well. And it's time to go to bed for me so I won't test it now. But here is the C# version:

      using System;

      class Test
      {
      static void Main()
      {
      double sum;
      // you can't use unintialized buffer in C#
      // and I though a new at each iteration was overkill
      char[] buf = new char[1024];
      for(uint i=0; i

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #38

      Super Lloyd wrote:

      and I though a new at each iteration was overkill

      Of course it is an overkill, but it is a benchmark, isn't it?

      Programming Blog utf8-cpp

      S 1 Reply Last reply
      0
      • S Super Lloyd

        On another thread some posted this link: http://www.csharphelp.com/archives2/archive458.html[^] Now I was very suprised by this bad C# result, it's not at all what I experience! So I decided to test my self! I have .NET 2 and gcc 3.4.4 I compiled like this: CPP> gcc -O3 -o sieve2.exe sieve.cpp -lstdc++ C#> csc /o+ /nologo /out:sieve.exe Sieve.cs I got: C# 10000 Milliseconds = 1156 C++ 10000 Milliseconds = 1313 Haheum..... what else can I say? -- modified at 11:18 Tuesday 1st August, 2006 I propose a Contest. Post a small C++ performance test program here (less than 200 readable lines). I'll try to beat it with a C# version!

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #39

        Uh, frankly, 95% of the time, I don't care. 95% of the time, the programmer writes such crappy code, performance is the least of my worries. Marc

        XPressTier

        Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
        People are just notoriously impossible. --DavidCrow
        There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer

        J S 2 Replies Last reply
        0
        • M Marc Clifton

          Uh, frankly, 95% of the time, I don't care. 95% of the time, the programmer writes such crappy code, performance is the least of my worries. Marc

          XPressTier

          Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
          People are just notoriously impossible. --DavidCrow
          There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer

          J Offline
          J Offline
          Josh Smith
          wrote on last edited by
          #40

          Marc Clifton wrote:

          Uh, frankly, 95% of the time, I don't care. 95% of the time, the programmer writes such crappy code, performance is the least of my worries.

          Amen, brother Marc! :-D

          :josh: My WPF Blog[^]

          R 1 Reply Last reply
          0
          • S Super Lloyd

            On another thread some posted this link: http://www.csharphelp.com/archives2/archive458.html[^] Now I was very suprised by this bad C# result, it's not at all what I experience! So I decided to test my self! I have .NET 2 and gcc 3.4.4 I compiled like this: CPP> gcc -O3 -o sieve2.exe sieve.cpp -lstdc++ C#> csc /o+ /nologo /out:sieve.exe Sieve.cs I got: C# 10000 Milliseconds = 1156 C++ 10000 Milliseconds = 1313 Haheum..... what else can I say? -- modified at 11:18 Tuesday 1st August, 2006 I propose a Contest. Post a small C++ performance test program here (less than 200 readable lines). I'll try to beat it with a C# version!

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #41

            Interesting Article (when including the links!) by Raymond Chen Clickety[^] Executive Summary: C++ wins, if you pull all tricks and invest to much time.


            Some of us walk the memory lane, others plummet into a rabbit hole
            Tree in C# || Fold With Us! || sighist

            1 Reply Last reply
            0
            • J Jeremy Falcon

              If I'm using MSVC, do you think it's really worth it to switch over to Intel's compiler? And, does it integrate into VS? Just curious to know, as I've never used it, but I've heard positive stories about it.

              Jeremy Falcon

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #42

              last time i used it, the integration was almost seamless. the performance wasn't much better, if at all, for my stuff. but i'd already optimized the hell out of my code with the MS compiler, so the Intel compiler didn't have much to work with. maybe if i'd given it more naive implementations, it would have done better against MS.

              Why donchoo take a peekchur mayn? OK, cleeeeek

              J 1 Reply Last reply
              0
              • S Super Lloyd

                On another thread some posted this link: http://www.csharphelp.com/archives2/archive458.html[^] Now I was very suprised by this bad C# result, it's not at all what I experience! So I decided to test my self! I have .NET 2 and gcc 3.4.4 I compiled like this: CPP> gcc -O3 -o sieve2.exe sieve.cpp -lstdc++ C#> csc /o+ /nologo /out:sieve.exe Sieve.cs I got: C# 10000 Milliseconds = 1156 C++ 10000 Milliseconds = 1313 Haheum..... what else can I say? -- modified at 11:18 Tuesday 1st August, 2006 I propose a Contest. Post a small C++ performance test program here (less than 200 readable lines). I'll try to beat it with a C# version!

                J Offline
                J Offline
                J Dunlap
                wrote on last edited by
                #43

                To me, it's not a big deal whether C# is exactly as fast as managed code for a particular scenario. What matters to me is that I've found that C# is fast enough that I can almost always write code that is as fast as or often faster than typical C++ code with little extra effort taken for the perf aspect. Other people's code, whether it be managed or unmanaged, is usually where I run into perf problems, and there's more than a few times that I've written extra managed code to get around a perf problem in 3rd-party unmanaged code that I'm interop'ing with.

                1 Reply Last reply
                0
                • J Josh Smith

                  Marc Clifton wrote:

                  Uh, frankly, 95% of the time, I don't care. 95% of the time, the programmer writes such crappy code, performance is the least of my worries.

                  Amen, brother Marc! :-D

                  :josh: My WPF Blog[^]

                  R Offline
                  R Offline
                  Roger Alsing 0
                  wrote on last edited by
                  #44

                  I 3rd that. Mix in a database and a bit of webservices and it wont matter any more.

                  http://www.puzzleframework.com

                  1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    If I'm using MSVC, do you think it's really worth it to switch over to Intel's compiler? And, does it integrate into VS? Just curious to know, as I've never used it, but I've heard positive stories about it.

                    Jeremy Falcon

                    E Offline
                    E Offline
                    El Corazon
                    wrote on last edited by
                    #45

                    Jeremy Falcon wrote:

                    If I'm using MSVC, do you think it's really worth it to switch over to Intel's compiler? And, does it integrate into VS? Just curious to know, as I've never used it, but I've heard positive stories about it.

                    It integrates pretty close to seamlessly into the VS environment. As for efficiency, that is a tough one. The Intel compiler does a better job at optimizing unoptimized code. If you are already an expert at writing optimized algorithms the only benefit would be seamless integration to VTune to let you hand-optimize your algorithms. We've had anywhere from 1% to 20% improvements.

                    _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                    J 1 Reply Last reply
                    0
                    • S Super Lloyd

                      On another thread some posted this link: http://www.csharphelp.com/archives2/archive458.html[^] Now I was very suprised by this bad C# result, it's not at all what I experience! So I decided to test my self! I have .NET 2 and gcc 3.4.4 I compiled like this: CPP> gcc -O3 -o sieve2.exe sieve.cpp -lstdc++ C#> csc /o+ /nologo /out:sieve.exe Sieve.cs I got: C# 10000 Milliseconds = 1156 C++ 10000 Milliseconds = 1313 Haheum..... what else can I say? -- modified at 11:18 Tuesday 1st August, 2006 I propose a Contest. Post a small C++ performance test program here (less than 200 readable lines). I'll try to beat it with a C# version!

                      E Offline
                      E Offline
                      El Corazon
                      wrote on last edited by
                      #46

                      Super Lloyd wrote:

                      So I decided to test my self!

                      Unfortunately algorithm makes the difference.... I noticed a few things.... The Vector version uses < char > so occupies less memory space and with multi-byte per-word is referenced via pointer very efficiently. I also got a slower response on an integer Array, but by dropping down to a character array like the vector, the speed improved. Second... never benchmark anything under a second or near a second. increase itterations until it is at least 10 seconds. you get a better benchmark, most benchmarks try for at least 30 seconds. If you want to bench in under a second, like time a single occurance of a function, use the CPU clock, this gives finer timing. I even found a project here that uses it. http://www.codeproject.com/datetime/ccputicker.asp[^] Third, every language has their uses. Trying to claim one language beats them all is a waste of time. Focus on the strong points, which C# has in abundance, and live with the rest without complaint. -- modified at 18:05 Tuesday 1st August, 2006

                      _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                      R 1 Reply Last reply
                      0
                      • C Chris Losinger

                        gcc is not exactly known for the speed of its code. try MSVC or Intel.

                        Why donchoo take a peekchur mayn? OK, cleeeeek

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #47

                        Chris Losinger wrote:

                        gcc is not exactly known for the speed of its code. try MSVC or Intel.

                        It sure beats MSVC with C. Dunno about other languages. Try it :)

                        **

                        xacc.ide-0.2.0.50 - now with partial MSBuild support!

                        **

                        C 1 Reply Last reply
                        0
                        • L leppie

                          Chris Losinger wrote:

                          gcc is not exactly known for the speed of its code. try MSVC or Intel.

                          It sure beats MSVC with C. Dunno about other languages. Try it :)

                          **

                          xacc.ide-0.2.0.50 - now with partial MSBuild support!

                          **

                          C Offline
                          C Offline
                          Chris Losinger
                          wrote on last edited by
                          #48

                          i don't have a gcc installation to try

                          Why donchoo take a peekchur mayn? OK, cleeeeek

                          1 Reply Last reply
                          0
                          • E El Corazon

                            Super Lloyd wrote:

                            So I decided to test my self!

                            Unfortunately algorithm makes the difference.... I noticed a few things.... The Vector version uses < char > so occupies less memory space and with multi-byte per-word is referenced via pointer very efficiently. I also got a slower response on an integer Array, but by dropping down to a character array like the vector, the speed improved. Second... never benchmark anything under a second or near a second. increase itterations until it is at least 10 seconds. you get a better benchmark, most benchmarks try for at least 30 seconds. If you want to bench in under a second, like time a single occurance of a function, use the CPU clock, this gives finer timing. I even found a project here that uses it. http://www.codeproject.com/datetime/ccputicker.asp[^] Third, every language has their uses. Trying to claim one language beats them all is a waste of time. Focus on the strong points, which C# has in abundance, and live with the rest without complaint. -- modified at 18:05 Tuesday 1st August, 2006

                            _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                            R Offline
                            R Offline
                            Roger Alsing 0
                            wrote on last edited by
                            #49

                            yeah, benchmarking itterations under 1sec there is a big chance that the .NET JIT is going to eat a big chunk of that time

                            http://www.puzzleframework.com

                            1 Reply Last reply
                            0
                            • C Chris Losinger

                              last time i used it, the integration was almost seamless. the performance wasn't much better, if at all, for my stuff. but i'd already optimized the hell out of my code with the MS compiler, so the Intel compiler didn't have much to work with. maybe if i'd given it more naive implementations, it would have done better against MS.

                              Why donchoo take a peekchur mayn? OK, cleeeeek

                              J Offline
                              J Offline
                              Jeremy Falcon
                              wrote on last edited by
                              #50

                              I'm thinking that is MSVC comes just about the same anyway, it's may not be worth the extra $800. :laugh: Thanks for the info.

                              Jeremy Falcon

                              1 Reply Last reply
                              0
                              • E El Corazon

                                Jeremy Falcon wrote:

                                If I'm using MSVC, do you think it's really worth it to switch over to Intel's compiler? And, does it integrate into VS? Just curious to know, as I've never used it, but I've heard positive stories about it.

                                It integrates pretty close to seamlessly into the VS environment. As for efficiency, that is a tough one. The Intel compiler does a better job at optimizing unoptimized code. If you are already an expert at writing optimized algorithms the only benefit would be seamless integration to VTune to let you hand-optimize your algorithms. We've had anywhere from 1% to 20% improvements.

                                _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

                                J Offline
                                J Offline
                                Jeremy Falcon
                                wrote on last edited by
                                #51

                                Jeffry J. Brickley wrote:

                                The Intel compiler does a better job at optimizing unoptimized code.

                                Well, I'd like to think my code is optimized, but that very well may not be the case. :laugh: Thanks for the info.

                                Jeremy Falcon

                                1 Reply Last reply
                                0
                                • S Super Lloyd

                                  Hey, I did optimize both! didn't you see the -O3 ?! Well the result are... well.... I didn't know gcc was that bad!.... :omg: That make me rethink about life! :laugh:

                                  J Offline
                                  J Offline
                                  Jorgen Sigvardsson
                                  wrote on last edited by
                                  #52

                                  Did you try -O2 for optimization? -O2 generally optimizes better than -O3. At least it did so back in the days. :)

                                  -- In Hypno-Vision

                                  S 1 Reply Last reply
                                  0
                                  • S Super Lloyd

                                    On another thread some posted this link: http://www.csharphelp.com/archives2/archive458.html[^] Now I was very suprised by this bad C# result, it's not at all what I experience! So I decided to test my self! I have .NET 2 and gcc 3.4.4 I compiled like this: CPP> gcc -O3 -o sieve2.exe sieve.cpp -lstdc++ C#> csc /o+ /nologo /out:sieve.exe Sieve.cs I got: C# 10000 Milliseconds = 1156 C++ 10000 Milliseconds = 1313 Haheum..... what else can I say? -- modified at 11:18 Tuesday 1st August, 2006 I propose a Contest. Post a small C++ performance test program here (less than 200 readable lines). I'll try to beat it with a C# version!

                                    J Offline
                                    J Offline
                                    Joe Woodbury
                                    wrote on last edited by
                                    #53

                                    A few months ago, I realized that time critical C# algorithm I was working on was similar to some C++ code I had worked on previously (no big surprise since I wrote both.) My curiosity got the better of me and I spent several hours setting up performance comparisons. One thing led to another and I ended up doing even more performance comparisons. I couldn't resist throwing the code into managed C++ and trying that. On average, FOR THESE TESTS, I found that the managed C++ code ran twice as fast as the C# code and the native C++ code ran twice as fast as the managed C++ code. There was one exception; I could fill a list box with thousands of items faster in C# than in native Win32 (The performance still stunk; I needed to fully virtualize both, but I'm not on that project any more so I don't care.)

                                    Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                                    1 Reply Last reply
                                    0
                                    • N Nemanja Trifunovic

                                      Super Lloyd wrote:

                                      and I though a new at each iteration was overkill

                                      Of course it is an overkill, but it is a benchmark, isn't it?

                                      Programming Blog utf8-cpp

                                      S Offline
                                      S Offline
                                      Super Lloyd
                                      wrote on last edited by
                                      #54

                                      it is not equal! in C++ it is just one instruction to move the stack pointer and not so in C#...

                                      N 1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        Uh, frankly, 95% of the time, I don't care. 95% of the time, the programmer writes such crappy code, performance is the least of my worries. Marc

                                        XPressTier

                                        Some people believe what the bible says. Literally. At least [with Wikipedia] you have the chance to correct the wiki -- Jörgen Sigvardsson
                                        People are just notoriously impossible. --DavidCrow
                                        There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer

                                        S Offline
                                        S Offline
                                        Super Lloyd
                                        wrote on last edited by
                                        #55

                                        I have no worry, I was already sold to C#. But it's just that all my test showed that C# is just as good as C++ speedwise, so I wanted to dispel the misperception! Unfortunately I was wrong and I also learnt that GCC is a slow compiler as well. It's all good mate! ;P

                                        1 Reply Last reply
                                        0
                                        • J Jorgen Sigvardsson

                                          Did you try -O2 for optimization? -O2 generally optimizes better than -O3. At least it did so back in the days. :)

                                          -- In Hypno-Vision

                                          S Offline
                                          S Offline
                                          Super Lloyd
                                          wrote on last edited by
                                          #56

                                          Okay, let's try! It's a little bit better, but still slower than C#

                                          J 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups