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. performance puzzle

performance puzzle

Scheduled Pinned Locked Moved The Lounge
questionc++performancecsharpcss
65 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.
  • A Aamir Butt

    Mechanical wrote:

    That is like looking for performance from Java: You won't get it.

    You are horribly wrong here. In some cases, C# can outperform C/C++ performance-wise. And that is because of the optimizations that can be made at intermediate-level i.e, IL or bytecode or whatever (which people like you think might be the reason for slowness). See here for a performance comparison between different languages[^] However, if you like to follow the sheep, go ahead.

    M Offline
    M Offline
    Mechanical
    wrote on last edited by
    #33

    Aamir Butt wrote:

    In some cases, C# can outperform C/C++

    How about ALL cases ? People who talk about C# (or any other retards' language) performance are talking about void while engaged with other C# (or any other retards' language) performance addicts in group masturbation. The link in your post points to another post by a C# guru (read as: VB guru). It says: "Remember : Engineers are expensive and servers are not!". Look at that! I mean just look at how pathetic that retard is.

    Aamir Butt wrote:

    However, if you like to follow the sheep, go ahead.

    I'll bet you are one of those that believe Java is the future of 3D.

    NULL

    A 1 Reply Last reply
    0
    • R realJSOP

      Super Lloyd wrote:

      Well, any C# performance tip is welcome!

      Uncle John's Handy C# Performance Tip #237: Convert the code to unmanaged C++.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #34

      :-D 5.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • L Lost User

        Post it?

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

        I already posted the source code: http://www.codeproject.com/Lounge.aspx?msg=3657380#xx3657380xx[^] As to the disassembly, err.... well, ok, but I have to cut the C++ version as it huge loads of stuff coming the #include(s), hopefully I'll cut it right ... disassembled JITted C#

        --- C:\Dev\Test\Performance\CSperf\Program.cs ----------------------------------
        if (args.Length != 1)
        00000000 push ebp
        00000001 mov ebp,esp
        00000003 push edi
        00000004 push esi
        00000005 sub esp,6Ch
        00000008 mov esi,ecx
        0000000a lea edi,[ebp-74h]
        0000000d mov ecx,1Bh
        00000012 xor eax,eax
        00000014 rep stos dword ptr es:[edi]
        00000016 mov ecx,esi
        00000018 mov dword ptr [ebp-0Ch],esp
        0000001b mov dword ptr [ebp-74h],2941BF9Bh
        00000022 mov dword ptr [ebp-60h],ecx
        00000025 cmp dword ptr ds:[001B7CB8h],0
        0000002c je 00000033
        0000002e call 62889E21
        00000033 xor edx,edx
        00000035 mov dword ptr [ebp-28h],edx
        00000038 xor edx,edx
        0000003a mov dword ptr [ebp-1Ch],edx
        0000003d xor edx,edx
        0000003f mov dword ptr [ebp-24h],edx
        00000042 xor edx,edx
        00000044 mov dword ptr [ebp-2Ch],edx
        00000047 xor edx,edx
        00000049 mov dword ptr [ebp-20h],edx
        0000004c xor edx,edx
        0000004e mov dword ptr [ebp-10h],edx
        00000051 mov eax,dword ptr [ebp-60h]
        00000054 cmp dword ptr [eax+4],1
        00000058 je 0000006B
        {
        Console.WriteLine("Usage:\tsieve [iterations]");
        0000005a mov ecx,dword ptr ds:[03832088h]
        00000060 call 62202DB4
        return;
        00000065 nop
        00000066 jmp 0000019A
        }

        		int NUM = int.Parse(args\[0\]);
        

        0000006b mov eax,dword ptr [ebp-60h]
        0000006e cmp dword ptr [eax+4],0
        00000072 ja 00000079
        00000074 call 6288BA5C
        00000079 mov ecx,dword ptr [eax+0Ch]
        0000007c call 6220EAC4
        00000081 mov dword ptr [ebp-38h],eax
        00000084 mov eax,dword ptr [ebp-38h]
        00000087 mov dword ptr [ebp-10h],eax
        var t0 = DateTime.Now;
        0000008a lea ecx,[ebp-40h]
        0000008d call 61D07768

        L D 2 Replies Last reply
        0
        • S Super Lloyd

          I already posted the source code: http://www.codeproject.com/Lounge.aspx?msg=3657380#xx3657380xx[^] As to the disassembly, err.... well, ok, but I have to cut the C++ version as it huge loads of stuff coming the #include(s), hopefully I'll cut it right ... disassembled JITted C#

          --- C:\Dev\Test\Performance\CSperf\Program.cs ----------------------------------
          if (args.Length != 1)
          00000000 push ebp
          00000001 mov ebp,esp
          00000003 push edi
          00000004 push esi
          00000005 sub esp,6Ch
          00000008 mov esi,ecx
          0000000a lea edi,[ebp-74h]
          0000000d mov ecx,1Bh
          00000012 xor eax,eax
          00000014 rep stos dword ptr es:[edi]
          00000016 mov ecx,esi
          00000018 mov dword ptr [ebp-0Ch],esp
          0000001b mov dword ptr [ebp-74h],2941BF9Bh
          00000022 mov dword ptr [ebp-60h],ecx
          00000025 cmp dword ptr ds:[001B7CB8h],0
          0000002c je 00000033
          0000002e call 62889E21
          00000033 xor edx,edx
          00000035 mov dword ptr [ebp-28h],edx
          00000038 xor edx,edx
          0000003a mov dword ptr [ebp-1Ch],edx
          0000003d xor edx,edx
          0000003f mov dword ptr [ebp-24h],edx
          00000042 xor edx,edx
          00000044 mov dword ptr [ebp-2Ch],edx
          00000047 xor edx,edx
          00000049 mov dword ptr [ebp-20h],edx
          0000004c xor edx,edx
          0000004e mov dword ptr [ebp-10h],edx
          00000051 mov eax,dword ptr [ebp-60h]
          00000054 cmp dword ptr [eax+4],1
          00000058 je 0000006B
          {
          Console.WriteLine("Usage:\tsieve [iterations]");
          0000005a mov ecx,dword ptr ds:[03832088h]
          00000060 call 62202DB4
          return;
          00000065 nop
          00000066 jmp 0000019A
          }

          		int NUM = int.Parse(args\[0\]);
          

          0000006b mov eax,dword ptr [ebp-60h]
          0000006e cmp dword ptr [eax+4],0
          00000072 ja 00000079
          00000074 call 6288BA5C
          00000079 mov ecx,dword ptr [eax+0Ch]
          0000007c call 6220EAC4
          00000081 mov dword ptr [ebp-38h],eax
          00000084 mov eax,dword ptr [ebp-38h]
          00000087 mov dword ptr [ebp-10h],eax
          var t0 = DateTime.Now;
          0000008a lea ecx,[ebp-40h]
          0000008d call 61D07768

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #36

          Are you sure you got the optimized version of the C# code? I mean, yea it's supposed to be lame, but it's worse than I expected

          S 1 Reply Last reply
          0
          • R realJSOP

            Super Lloyd wrote:

            Well, any C# performance tip is welcome!

            Uncle John's Handy C# Performance Tip #237: Convert the code to unmanaged C++.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

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

            Well it's only tip #237, so I guess it's not the 1st thing I should rush to do! :)

            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

            P D 2 Replies Last reply
            0
            • M Mechanical

              Super Lloyd wrote:

              any C# performance tip is welcome!

              That is like looking for performance from Java: You won't get it. If you need (or want) performance, don't do retards' languages. I know this thread isn't meant to incite hatred against retards' languages.

              NULL

              D Offline
              D Offline
              Derek Viljoen
              wrote on last edited by
              #38

              Mechanical, I checked your profile. You've never authored an article, posted a snippet, entered a blog post, or otherwise shared any original thought, except to snipe at other people's comments on the message boards. In other words, you have yet to provide any empirical evidence for your worth to this site. No be a good boy and go away, please.

              M 1 Reply Last reply
              0
              • M Mechanical

                My statement was made because I had to maintain some Native code I wrote some years ago. I realized how retarded I had become doing retards' languages.

                peterchen wrote:

                Are you open to evidence for my statement

                I'm all ears (big, pointy ears).

                NULL

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

                The Raymond Chen vs. Rico Mariani competition comes to mind. Clickety[^] Clickety-Click[^] The final result, at first look, supports your statement: The C++ version completed before the .NET application even did load. However, when you look at the history and details, you see that the road to the superfast C++ application was a rocky one, introducing subtle bugs and requiring a very experienced developer to counter the rather simple improvements to the C# solution.


                With extensions like LINQ, Closures, Lambdas, Generics and some syntactic sugar, C# has become a rather complex and powerful language. It's complex and powerful in a different sense than C++, but still.

                Agh! Reality! My Archnemesis![^]
                | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                modified on Friday, November 5, 2010 11:17 AM

                1 Reply Last reply
                0
                • S Super Lloyd

                  Well it's only tip #237, so I guess it's not the 1st thing I should rush to do! :)

                  A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

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

                  Hey! Take stop reading my mind!

                  Agh! Reality! My Archnemesis![^]
                  | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                  1 Reply Last reply
                  0
                  • D DaveAuld

                    Nothing to do with the optimisation, but what about using the StopWatch class instead of datetime? Start the stop watch immediately before you enter the loop, and then stop it as soon as the loop exists.

                    Dave Find Me On: Web|Facebook|Twitter|LinkedIn CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #41

                    I agree. On my machine 10 iterations take 0.5 milliseconds, which DateTime.Now can't catch at all. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    1 Reply Last reply
                    0
                    • S Super Lloyd

                      I already posted the source code: http://www.codeproject.com/Lounge.aspx?msg=3657380#xx3657380xx[^] As to the disassembly, err.... well, ok, but I have to cut the C++ version as it huge loads of stuff coming the #include(s), hopefully I'll cut it right ... disassembled JITted C#

                      --- C:\Dev\Test\Performance\CSperf\Program.cs ----------------------------------
                      if (args.Length != 1)
                      00000000 push ebp
                      00000001 mov ebp,esp
                      00000003 push edi
                      00000004 push esi
                      00000005 sub esp,6Ch
                      00000008 mov esi,ecx
                      0000000a lea edi,[ebp-74h]
                      0000000d mov ecx,1Bh
                      00000012 xor eax,eax
                      00000014 rep stos dword ptr es:[edi]
                      00000016 mov ecx,esi
                      00000018 mov dword ptr [ebp-0Ch],esp
                      0000001b mov dword ptr [ebp-74h],2941BF9Bh
                      00000022 mov dword ptr [ebp-60h],ecx
                      00000025 cmp dword ptr ds:[001B7CB8h],0
                      0000002c je 00000033
                      0000002e call 62889E21
                      00000033 xor edx,edx
                      00000035 mov dword ptr [ebp-28h],edx
                      00000038 xor edx,edx
                      0000003a mov dword ptr [ebp-1Ch],edx
                      0000003d xor edx,edx
                      0000003f mov dword ptr [ebp-24h],edx
                      00000042 xor edx,edx
                      00000044 mov dword ptr [ebp-2Ch],edx
                      00000047 xor edx,edx
                      00000049 mov dword ptr [ebp-20h],edx
                      0000004c xor edx,edx
                      0000004e mov dword ptr [ebp-10h],edx
                      00000051 mov eax,dword ptr [ebp-60h]
                      00000054 cmp dword ptr [eax+4],1
                      00000058 je 0000006B
                      {
                      Console.WriteLine("Usage:\tsieve [iterations]");
                      0000005a mov ecx,dword ptr ds:[03832088h]
                      00000060 call 62202DB4
                      return;
                      00000065 nop
                      00000066 jmp 0000019A
                      }

                      		int NUM = int.Parse(args\[0\]);
                      

                      0000006b mov eax,dword ptr [ebp-60h]
                      0000006e cmp dword ptr [eax+4],0
                      00000072 ja 00000079
                      00000074 call 6288BA5C
                      00000079 mov ecx,dword ptr [eax+0Ch]
                      0000007c call 6220EAC4
                      00000081 mov dword ptr [ebp-38h],eax
                      00000084 mov eax,dword ptr [ebp-38h]
                      00000087 mov dword ptr [ebp-10h],eax
                      var t0 = DateTime.Now;
                      0000008a lea ecx,[ebp-40h]
                      0000008d call 61D07768

                      D Offline
                      D Offline
                      Daniel Grunwald
                      wrote on last edited by
                      #42

                      You need to be careful, the JIT will turn off optimizations when running inside the Visual Studio debugger (even in release builds!). To get the optimized JITted assembly code, you need to run your program from the command line, then attach the debugger to the running process, and click Break.

                      S 1 Reply Last reply
                      0
                      • S Super Lloyd

                        yes, do post back please! :P

                        A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                        S Offline
                        S Offline
                        Simon P Stevens
                        wrote on last edited by
                        #43

                        Well I've written a C# version that runs 15-20% faster that your original on my PC. It doesn't use unsafe either. But I don't think you'll like it.

                        private static void SafeTest_Improved1(string[] args)
                        {
                        int NUM = int.Parse(args[0]);
                        int end = 8193;
                        var primes = new byte[8193]{
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

                            1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
                        
                        S 1 Reply Last reply
                        0
                        • D Daniel Grunwald

                          You need to be careful, the JIT will turn off optimizations when running inside the Visual Studio debugger (even in release builds!). To get the optimized JITted assembly code, you need to run your program from the command line, then attach the debugger to the running process, and click Break.

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

                          To test the speed I was running each program from the command line! ^_^

                          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                          D 1 Reply Last reply
                          0
                          • S Super Lloyd

                            To test the speed I was running each program from the command line! ^_^

                            A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                            D Offline
                            D Offline
                            Daniel Grunwald
                            wrote on last edited by
                            #45

                            Yes but where did you get the disassembled C# code from? It looks like all locals are on the stack (never in registers), which the JIT normally does only when a debugger is attached.

                            S 1 Reply Last reply
                            0
                            • L Lost User

                              Are you sure you got the optimized version of the C# code? I mean, yea it's supposed to be lame, but it's worse than I expected

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

                              Yes it! :( Is it that bad? I'm not that conversant in ASM, so I couldn't tell... But in a way that's good news, they have room for improvement! Now, what are they waiting for!?! :rolleyes:

                              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                              1 Reply Last reply
                              0
                              • D Daniel Grunwald

                                Yes but where did you get the disassembled C# code from? It looks like all locals are on the stack (never in registers), which the JIT normally does only when a debugger is attached.

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

                                Ha, the disassembly I got it from VS! Not sure how to get it otherwise... Because on the disk it's not compiled, it's just MSIL, and even if I NGen I dunno where they store the compiled version! (BTW I just tried NGen and it was not faster!?!)

                                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                D 1 Reply Last reply
                                0
                                • M Mechanical

                                  Aamir Butt wrote:

                                  In some cases, C# can outperform C/C++

                                  How about ALL cases ? People who talk about C# (or any other retards' language) performance are talking about void while engaged with other C# (or any other retards' language) performance addicts in group masturbation. The link in your post points to another post by a C# guru (read as: VB guru). It says: "Remember : Engineers are expensive and servers are not!". Look at that! I mean just look at how pathetic that retard is.

                                  Aamir Butt wrote:

                                  However, if you like to follow the sheep, go ahead.

                                  I'll bet you are one of those that believe Java is the future of 3D.

                                  NULL

                                  A Offline
                                  A Offline
                                  Aamir Butt
                                  wrote on last edited by
                                  #48

                                  Mechanical wrote:

                                  I'll bet you are one of those that believe Java is the future of 3D.

                                  Java... Hahahaha... well I can't stop laughing. I haven't worked in Java since school. And I bet you are the one who writes all his linked list, hashtable, search and sorting algorithm from scratch because he believes that he can do better than those retards.

                                  Mechanical wrote:

                                  How about ALL cases ?

                                  Well, give me a case you are talking about but before that, give me the name of a NON-RETARD language as per your understanding.

                                  1 Reply Last reply
                                  0
                                  • D DaveAuld

                                    Nothing to do with the optimisation, but what about using the StopWatch class instead of datetime? Start the stop watch immediately before you enter the loop, and then stop it as soon as the loop exists.

                                    Dave Find Me On: Web|Facebook|Twitter|LinkedIn CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.

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

                                    well, I run 10000 thousand iteration to compare them, so DateTime seems precise enough! :) I did use StopWatch in the past but, I dunno, was never converted to it, I guess I never needed to make measurement precise enough!

                                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                    1 Reply Last reply
                                    0
                                    • S Super Lloyd

                                      Ha, the disassembly I got it from VS! Not sure how to get it otherwise... Because on the disk it's not compiled, it's just MSIL, and even if I NGen I dunno where they store the compiled version! (BTW I just tried NGen and it was not faster!?!)

                                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                      D Offline
                                      D Offline
                                      Daniel Grunwald
                                      wrote on last edited by
                                      #50

                                      Super Lloyd wrote:

                                      Ha, the disassembly I got it from VS! Not sure how to get it otherwise...

                                      To get the optimized JITted assembly code, you need to run your program from the command line, then attach the debugger to the running process, and click Break. Because your Main function was already running before you attached the debugger, it will still have the real native code. .NET doesn't re-jit anything when attaching a debugger.

                                      S 1 Reply Last reply
                                      0
                                      • D Dan Neely

                                        Aamir Butt wrote:

                                        See here for a performance comparison between different languages[^]

                                        The comments on that post were staggeringly stupid. :((

                                        3x12=36 2x12=24 1x12=12 0x12=18

                                        A Offline
                                        A Offline
                                        Aamir Butt
                                        wrote on last edited by
                                        #51

                                        Dan Neely wrote:

                                        The comments on that post were staggeringly stupid.

                                        Yes, unfortunately. There are other performance comparisons as well but there is no point in posting the links here. As i said earlier, following the sheep..... :)

                                        1 Reply Last reply
                                        0
                                        • S Simon P Stevens

                                          Well I've written a C# version that runs 15-20% faster that your original on my PC. It doesn't use unsafe either. But I don't think you'll like it.

                                          private static void SafeTest_Improved1(string[] args)
                                          {
                                          int NUM = int.Parse(args[0]);
                                          int end = 8193;
                                          var primes = new byte[8193]{
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

                                              1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
                                          
                                          S Offline
                                          S Offline
                                          Super Lloyd
                                          wrote on last edited by
                                          #52

                                          :laugh: you could have moved the "for(...) prims[i] = 1" statement out of the loop for the same (and more condensed) result! But this is an unfair comparison with C++, you removed a whole set a "required" operation for the algorithm! Although... I wonder if an array copy from an initialized array would speed up things....

                                          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                          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