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.
  • R Rama Krishna Vavilala

    Ahem.. Good old article[^]


    My Blog

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

    Good!

    1 Reply Last reply
    0
    • C Chris Losinger

      Super Lloyd wrote:

      Is it .NET2??

      yes

      Why donchoo take a peekchur mayn? OK, cleeeeek

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

      Alright, you won! ;)

      1 Reply Last reply
      0
      • S Super Lloyd

        AMD Sempron 2800+ 1.61 GHz No wonder you are twice as fast!

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

        Super Lloyd wrote:

        No wonder you are twice as fast!

        grumble grumble growl... you made me pull out my 7.2 .net on the laptop, compile, move the application over and run... ;P 1000ms C# 562 Intel C++ Satisfied yet? yes, I moved to release on both, yes, using optimized on both rather than YOUR optimized on one and non on the other....

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

        S 1 Reply Last reply
        0
        • E El Corazon

          Super Lloyd wrote:

          No wonder you are twice as fast!

          grumble grumble growl... you made me pull out my 7.2 .net on the laptop, compile, move the application over and run... ;P 1000ms C# 562 Intel C++ Satisfied yet? yes, I moved to release on both, yes, using optimized on both rather than YOUR optimized on one and non on the other....

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

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

          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 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!

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

            Super Lloyd wrote:

            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!

            From the top of my head:

            #include <iostream>
            using namespace std;

            int main()
            {
            double sum = 0.;
            for (unsigned i = 0; i < 0xffffffU; ++i) {
            char buffer[1024];
            for (int j = 0; j < 1024; ++j)
            sum += buffer[j];
            }
            cout << sum;
            }

            -- modified at 12:20 Tuesday 1st August, 2006

            Programming Blog utf8-cpp

            S 1 Reply Last reply
            0
            • S Super Lloyd

              AMD Sempron 2800+ 1.61 GHz No wonder you are twice as fast!

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

              Super Lloyd wrote:

              AMD Sempron 2800+ 1.61 GHz No wonder you are twice as fast!

              I just looked at your specs... you realize that the 2800+ is the relative performance compared to an Intel right? My AMD is only 1.8ghz and runs faster than this one at work. I don't have any of my fast computers at the moment. :)

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

              1 Reply Last reply
              0
              • S Super Lloyd

                I tried cl /O2 /EHsc sieve.cpp It compiled without any message but crashed right away... Now, if C++ is so much more powerfull, why do I need an optimized compiler? :doh:

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

                Super Lloyd wrote:

                Now, if C++ is so much more powerfull, why do I need an optimized compiler?

                You obviously have no clue as to the difference between what a compiler is and what a language is.

                Jeremy Falcon

                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!

                  L Offline
                  L Offline
                  Landarzar
                  wrote on last edited by
                  #31

                  can you please post the source of you Sieve.cs and sieve.cpp...

                  S 1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    Super Lloyd wrote:

                    Now, if C++ is so much more powerfull, why do I need an optimized compiler?

                    You obviously have no clue as to the difference between what a compiler is and what a language is.

                    Jeremy Falcon

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

                    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 1 Reply Last reply
                    0
                    • L Landarzar

                      can you please post the source of you Sieve.cs and sieve.cpp...

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

                      I simply took the sources from the article: http://www.csharphelp.com/archives2/archive458.html[^]

                      1 Reply Last reply
                      0
                      • E El Corazon

                        Super Lloyd wrote:

                        Hey, GCC is not so bad!

                        Nope, it's only slower than C#, that is a great selling point! :laugh:

                        _________________________ 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
                        #34

                        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 E 2 Replies Last reply
                        0
                        • N Nemanja Trifunovic

                          Super Lloyd wrote:

                          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!

                          From the top of my head:

                          #include <iostream>
                          using namespace std;

                          int main()
                          {
                          double sum = 0.;
                          for (unsigned i = 0; i < 0xffffffU; ++i) {
                          char buffer[1024];
                          for (int j = 0; j < 1024; ++j)
                          sum += buffer[j];
                          }
                          cout << sum;
                          }

                          -- modified at 12:20 Tuesday 1st August, 2006

                          Programming Blog utf8-cpp

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

                          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 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!

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

                            Time to go to bed... But I wonder if someone could be so kind to redo the test with a 3rd compiler & language (actuially run the 3 test on its computer, so we could compare!) The C++ & C# version http://www.csharphelp.com/archives2/archive458.html[^] and the D version! The source is there: http://www.digitalmars.com/d/overview.html[^] At the end of the page. And the compiler could be downloaded from there[^].

                            1 Reply Last reply
                            0
                            • 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
                                          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