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. General Programming
  3. C#
  4. Performence in c#

Performence in c#

Scheduled Pinned Locked Moved C#
questioncsharpcode-review
36 Posts 9 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.
  • N Niklas Ulvinge

    Writeline is important for me... It's my debugger... Now I write almost everyting in asm, as it's so fast and easy to get. It got enought documentation to make me sick, that's the way I love it. The one and only Niklas Ulvinge aka IDK

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

    I also like to use Console.WriteLine for debugging. WriteLine is slower than PRINT, but both write extremly faster than you can read the output. If your output is useful for debugging, it probably isn't so long that it can have any impact on the program.

    N 1 Reply Last reply
    0
    • D Daniel Grunwald

      I also like to use Console.WriteLine for debugging. WriteLine is slower than PRINT, but both write extremly faster than you can read the output. If your output is useful for debugging, it probably isn't so long that it can have any impact on the program.

      N Offline
      N Offline
      Niklas Ulvinge
      wrote on last edited by
      #19

      One example of the performance loss of the Console.WriteLine func is when debugging the program to calc pi. Since it goes in very fast loop it is very slow. If you think my program was a bad example, I got a NN program that's built in C#. It needs to write variables at runtime every loop. The one and only Niklas Ulvinge aka IDK

      1 Reply Last reply
      0
      • N Niklas Ulvinge

        No, but it's faster. The one and only Niklas Ulvinge aka IDK

        S Offline
        S Offline
        Stanciu Vlad
        wrote on last edited by
        #20

        I have only one reply : LOL But not a simple LOL, a very loud LOL. I have never seen such a stubborn man. Btw, Niklas I wish you luck in writing an ERP in assembler :) I hope you understand...because is a rough world out there...

        N 1 Reply Last reply
        0
        • S Stanciu Vlad

          I have only one reply : LOL But not a simple LOL, a very loud LOL. I have never seen such a stubborn man. Btw, Niklas I wish you luck in writing an ERP in assembler :) I hope you understand...because is a rough world out there...

          N Offline
          N Offline
          Niklas Ulvinge
          wrote on last edited by
          #21

          What would be hard to write an ERP in assembler? The one and only Niklas Ulvinge aka IDK

          1 Reply Last reply
          0
          • N Niklas Ulvinge

            That was the point. C#'s out func and a lot other funcs it got is really slow. The one and only Niklas Ulvinge aka IDK

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #22

            Niklas Ulvinge wrote:

            C#'s out func and a lot other funcs it got is really slow.

            But, that isn't C# it is the .NET Framework.


            My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

            N 1 Reply Last reply
            0
            • C Colin Angus Mackay

              Niklas Ulvinge wrote:

              C#'s out func and a lot other funcs it got is really slow.

              But, that isn't C# it is the .NET Framework.


              My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

              N Offline
              N Offline
              Niklas Ulvinge
              wrote on last edited by
              #23

              OK, I meant the .NET framework... C# is compiled to msil, wich is the .net framework language... Another way of writing it is: The out func of C# and a lot other funcs it got is really slow Wich meant what I meant... The one and only Niklas Ulvinge aka IDK

              C 1 Reply Last reply
              0
              • N Niklas Ulvinge

                Writeline is important for me... It's my debugger... Now I write almost everyting in asm, as it's so fast and easy to get. It got enought documentation to make me sick, that's the way I love it. The one and only Niklas Ulvinge aka IDK

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #24

                Niklas Ulvinge wrote:

                Writeline is important for me... It's my debugger...

                Is that important to your customer? will they be looking at debugging statements?


                My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                N 1 Reply Last reply
                0
                • N Niklas Ulvinge

                  OK, I meant the .NET framework... C# is compiled to msil, wich is the .net framework language... Another way of writing it is: The out func of C# and a lot other funcs it got is really slow Wich meant what I meant... The one and only Niklas Ulvinge aka IDK

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #25

                  What I'm getting at is that C# isn't slow. The particular method you are using is slow because it takes into account a whole host of things like culture, formatting options and so on. If you only ever want to output something in a very simple way then Console.WriteLine is too feature rich, and that is what you are paying for. There is nothing stopping you from providing your own implementation if you need speed.


                  My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                  N 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    Niklas Ulvinge wrote:

                    Writeline is important for me... It's my debugger...

                    Is that important to your customer? will they be looking at debugging statements?


                    My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                    N Offline
                    N Offline
                    Niklas Ulvinge
                    wrote on last edited by
                    #26

                    I don't got any costomers... I don't think all the 2,3 million members on this site have... The one and only Niklas Ulvinge aka IDK

                    C 1 Reply Last reply
                    0
                    • C Colin Angus Mackay

                      What I'm getting at is that C# isn't slow. The particular method you are using is slow because it takes into account a whole host of things like culture, formatting options and so on. If you only ever want to output something in a very simple way then Console.WriteLine is too feature rich, and that is what you are paying for. There is nothing stopping you from providing your own implementation if you need speed.


                      My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                      N Offline
                      N Offline
                      Niklas Ulvinge
                      wrote on last edited by
                      #27

                      Thats true. I didn't think of that... But how do I access the memmory at 0xA000 ? The one and only Niklas Ulvinge aka IDK

                      C 1 Reply Last reply
                      0
                      • N Niklas Ulvinge

                        I don't got any costomers... I don't think all the 2,3 million members on this site have... The one and only Niklas Ulvinge aka IDK

                        C Offline
                        C Offline
                        Colin Angus Mackay
                        wrote on last edited by
                        #28

                        Ah-hah!!! Now we get to the reason for this.... I was about to recommend this article[^] but you probably won't need that just yet. But, it is a good read and there are important points in it that are good to know if you wish to go for a career in Software Development in the future.


                        My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                        N 1 Reply Last reply
                        0
                        • C Colin Angus Mackay

                          Ah-hah!!! Now we get to the reason for this.... I was about to recommend this article[^] but you probably won't need that just yet. But, it is a good read and there are important points in it that are good to know if you wish to go for a career in Software Development in the future.


                          My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                          N Offline
                          N Offline
                          Niklas Ulvinge
                          wrote on last edited by
                          #29

                          I've already read about that in another book... Almost all asm books have a section like that in it. The one and only Niklas Ulvinge aka IDK

                          1 Reply Last reply
                          0
                          • N Niklas Ulvinge

                            Thats true. I didn't think of that... But how do I access the memmory at 0xA000 ? The one and only Niklas Ulvinge aka IDK

                            C Offline
                            C Offline
                            Colin Angus Mackay
                            wrote on last edited by
                            #30

                            Looking at how the Console class works, eventually there is some PInvoking of some native methods to get a handle on the stanard out (stdout) stream.

                            public static Stream OpenStandardOutput(int bufferSize)
                            {
                            return Console.GetStandardFile(-11, FileAccess.Write, bufferSize);
                            }

                            private static Stream GetStandardFile(int stdHandleName, FileAccess access, int bufferSize)
                            {
                            IntPtr ptr1 = Win32Native.GetStdHandle(stdHandleName);
                            if (ptr1 == Win32Native.INVALID_HANDLE_VALUE)
                            {
                            return Stream.Null;
                            }
                            if (ptr1 == IntPtr.Zero)
                            {
                            return Stream.Null;
                            }
                            if ((stdHandleName != -10) && (Console.ConsoleHandleIsValidNative(ptr1) == 0))
                            {
                            return Stream.Null;
                            }
                            return new __ConsoleStream(ptr1, access);
                            }

                            [DllImport("kernel32.dll", SetLastError=true)]
                            internal static extern IntPtr GetStdHandle(int nStdHandle);

                            You could just get the stream and operate on it directly.


                            My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                            N 1 Reply Last reply
                            0
                            • C Colin Angus Mackay

                              Looking at how the Console class works, eventually there is some PInvoking of some native methods to get a handle on the stanard out (stdout) stream.

                              public static Stream OpenStandardOutput(int bufferSize)
                              {
                              return Console.GetStandardFile(-11, FileAccess.Write, bufferSize);
                              }

                              private static Stream GetStandardFile(int stdHandleName, FileAccess access, int bufferSize)
                              {
                              IntPtr ptr1 = Win32Native.GetStdHandle(stdHandleName);
                              if (ptr1 == Win32Native.INVALID_HANDLE_VALUE)
                              {
                              return Stream.Null;
                              }
                              if (ptr1 == IntPtr.Zero)
                              {
                              return Stream.Null;
                              }
                              if ((stdHandleName != -10) && (Console.ConsoleHandleIsValidNative(ptr1) == 0))
                              {
                              return Stream.Null;
                              }
                              return new __ConsoleStream(ptr1, access);
                              }

                              [DllImport("kernel32.dll", SetLastError=true)]
                              internal static extern IntPtr GetStdHandle(int nStdHandle);

                              You could just get the stream and operate on it directly.


                              My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

                              N Offline
                              N Offline
                              Niklas Ulvinge
                              wrote on last edited by
                              #31

                              But that's still slower than basic... The one and only Niklas Ulvinge aka IDK

                              L 1 Reply Last reply
                              0
                              • N Niklas Ulvinge

                                But that's still slower than basic... The one and only Niklas Ulvinge aka IDK

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

                                Niklas Ulvinge wrote:

                                But that's still slower than basic...

                                If we trust you to even write QBASIC that is.... xacc.ide-0.1-rc4 released! Download and screenshots

                                N 1 Reply Last reply
                                0
                                • N Niklas Ulvinge

                                  Writeline is important for me... It's my debugger... Now I write almost everyting in asm, as it's so fast and easy to get. It got enought documentation to make me sick, that's the way I love it. The one and only Niklas Ulvinge aka IDK

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

                                  How can you use debugging and performance in the same sentence? xacc.ide-0.1-rc4 released! Download and screenshots

                                  N 1 Reply Last reply
                                  0
                                  • L leppie

                                    Niklas Ulvinge wrote:

                                    But that's still slower than basic...

                                    If we trust you to even write QBASIC that is.... xacc.ide-0.1-rc4 released! Download and screenshots

                                    N Offline
                                    N Offline
                                    Niklas Ulvinge
                                    wrote on last edited by
                                    #34

                                    What do you mean? The one and only Niklas Ulvinge aka IDK

                                    1 Reply Last reply
                                    0
                                    • L leppie

                                      How can you use debugging and performance in the same sentence? xacc.ide-0.1-rc4 released! Download and screenshots

                                      N Offline
                                      N Offline
                                      Niklas Ulvinge
                                      wrote on last edited by
                                      #35

                                      It's boring to wait 5 min for a thing to complete when you debug... The one and only Niklas Ulvinge aka IDK

                                      1 Reply Last reply
                                      0
                                      • N Niklas Ulvinge

                                        Think out the fastest algorithm. Then implement it the fastest way. C# is very slow, and the compiler can optimize better than you so you can't do anything. Learn asm and you'll get the best performance, both of your mind and of your computer. The one and only Niklas Ulvinge aka IDK

                                        M Offline
                                        M Offline
                                        mcljava
                                        wrote on last edited by
                                        #36

                                        Gee whiz, considering that 2GL and early 3GL compilers and linkers had very few commands to operate on compared to today's super compilers it's realy no surprise. However just because C# might not be the fastest language ever invented, development time is cut down, and oh btw, good luck on trying to write a GUI, TCP/IP stream processor, and SQL interface using Assembler. Yeah you could do it but for what purpose? I used to be an assembler programmer (back in the 80s!) and I'll admit to being concerned about shaving cycles and optimizing every instruction. But those are memories I'll gladly leave behind. Mike

                                        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