Performence in c#
-
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
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.
-
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.
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
-
No, but it's faster. The one and only Niklas Ulvinge aka IDK
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...
-
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...
What would be hard to write an ERP in assembler? The one and only Niklas Ulvinge aka IDK
-
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
-
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
-
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
-
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
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
-
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
But that's still slower than basic... The one and only Niklas Ulvinge aka IDK
-
But that's still slower than basic... The one and only Niklas Ulvinge aka IDK
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
-
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
How can you use debugging and performance in the same sentence? xacc.ide-0.1-rc4 released! Download and screenshots
-
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
What do you mean? The one and only Niklas Ulvinge aka IDK
-
How can you use debugging and performance in the same sentence? xacc.ide-0.1-rc4 released! Download and screenshots
It's boring to wait 5 min for a thing to complete when you debug... The one and only Niklas Ulvinge aka IDK
-
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
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