|
I have an AMD 64 (3500+) here. Oh, and I used a release build without integer overflow checks, which again is unfair since QBasic does not support those optimizations.
But I think there's no way to create a fair benchmark.
You can create a benchmark that shows pretty much anything if you want.
Write to the console and QBasic is faster than C#.
Use Math.Sin and C# is 50 times faster than Java 1.4.
Construct lots of objects on the heap and C# is faster than C (without using memory pooling).
So the best language always depends on what you want to do. If you need optimal performance, C is the way to go (maybe even use assembler for some sections).
C# is pretty fast, but it's easy to ruin performance by using some slow method. But this is the same as in every language, some functions always are slow.
Console.WriteLine is something that is not performance-critical in nearly all C# applications, so it didn't made sense for Microsoft to write a fast implementation.
You get much better performance in C# if you write to a file instead of the console.
As a side note, there are algorithms that need only 50 iterations to get PI so exactly as a double can store it.
What other .NET functions do you think are slow and would be useful inside critical loops? Console.WriteLine is not one of those for me.
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
It's boring to wait 5 min for a thing to complete when you debug...
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
Have you only come to this forum to post such crap?
Have you tried to understand what Daniel was saying?
Console.WriteLine as a very complex beast. You can feed it with any kind of data and it will print it out different ways automatically depending on the set culture. Is QBasic also able to do this with its PRINT function?
|
|
|
|
|
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...
|
|
|
|
|
What would be hard to write an ERP in assembler?
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
But that's still slower than basic...
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
|
What do you mean?
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
Could you please test the same without PRINT and Console.WriteLine?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
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
|
|
|
|
|
Hi all,
I wanna write a program that can monitor and discover any change of file in windows sytem and notify the change to user. where should i begin and what should i read ?
Thanks,
ken
|
|
|
|