How are you guys? I hope that everyone is OK.
Of course all of you know that VS.NET 2008 had released, and there is lots of guys downloaded it, and most of them until now are very happy with the nice IDE and the new features, I liked one thing about the new VS, it is the ability to debug in the .NET framework 3.5 , I have downloaded the new version of VS.NET (2008), I installed it and I start doing the thing that interest me which is debugging in the GREAT DOT NET FRAMEWORK, actually I was trying something so simple, I wanted to change the window title, the code was nothing as I think
this.Text = "New Title";
then I got into the code, and I got shocked, there is hell of processing happen to just set the window title, I didn't imagine that it is like that, I though that there is something wrong, so I go and write some code to test the performance
After I wrote the code I run the application in very normal way, and here is the result (I will explain what did that application do)
simply the application changes the window name 10000 times, and count the ticks using (GetTickCount)
it uses 2 techniques framework code "this.Text" and the Native Method which is using the API "SetWindowText"
and as you can see the snapshot, native is faster than the framework with about 70%,
the point here that the dot NET framework have lots of checks before doing the command, somehow it is necessary, in same time it is time consuming, as I think at certain point if you are really seeking for the performance you will get to the Native as your saver, I know that what I am talking about is not new, but many people are ignoring the performance issue, I am sure that .NET has many performance weakness, for many reasons, now I hope that you like this post and do some tests your self to see what I am talking about , I hope that the post was informative, thanks for your time
BR
Ahmed Essam
9 comments:
that is pretty very normal and expected, managed code is ofcourse is slower than native code
but there are advantages that is availble to the managed code and not for the native code and thats why the cost
I would not simply assume that .NET code is slower than Native just based on such one example. There will be cases where it is slower and there will be cases where it is faster. The best way to check is to measure, which is what you did in this case - great!
Also mind that you measured performance of WinForms framework vs. Win32 API. That is not the same as .NET (framework) vs. Native code. The WinForms does more, as you've noticed, so it takes more time.
Hi Maciek
The idea is there is lots of validation in the code when I have traced it, what I am talking about is some how dot NET framework need some kind of enhancement to control all of this validation, it is really to many checks, this checks aren't for free, it cost performance, dot NET is cool if you are talking about productivity, but in certain points it is the best way, in my work we do lots of C++ development, actually we do component to be consumed by dot NET, such thing is critical if your clients care about performance, but there is no doubt that dot NET framework is AMAMZING thing to save lots of time.
By the way, I perfrom the test with Win32 application and the result was 60% saved time more than the dot NET one.
Thanks for your time.
BR
Ahemd Essam
Alsalam alikom wa r7mat Allah wa barakatoh,
I believe using .NET is not only for safty/checks or whatever... it's also for portability, relying on Win32 APIs kills your portability ot other platforms (using mono most probably)
I agree with you that performance at some points will degrade if you used .NET rather than native calls... looking at the bright side and seeing the .NET Micro being installed on Ethernet cards... ur commercial processor may eventually run MSIL as it now runs assembly...
if your code will not really get benefit of those milliseconds difference, then I believe sticking to pure .NET code worth it.
Thanks,
Haytham Alaa
Peace be upon you
Welcome Haytham,
what you are talking about is totally true, if it is relying on Win32 APIs then it is done, this what COSMOS, portability issues, COSMOS is new FULLY managed Operating system, its idea is AMAZING, the guys did some engine called "IL2CPU" this converts the MSIL to Assembly code, which means that it is not good to have Inter Op things a round .NET code, because some how it will need to have runnable native code to complete the rest, in other hand there is Singularity it is not like COSMOS, in Singularity they admit that they have performances issues which means, the idea it self is not that good
over all, nothing will work better than the native MACHINE code, forget about IL(it means anything related to dot NET) or anything similar to it, the IDEA of VM like JAVA byte code and Microsoft Intermediate language all of that add performance over head on the machine, but I have to admit that something like COSMOS is GREAT idea, because it will convert the IL code in the end to MACHINE code, but it will also will have some issues, the issues will be in optimizing the application, but who knows may be it become better than anything,
but as you can see that COSMOS, has nothing to do with Portability, it may be CODE portable not binary portable which means at the end you are not under the umbrella of managed you are just got compiled under the managed umbrella then the umbrella is no more needed, because it is the machine code that will be used for life, you don't need to recompile or JIT or NGEN it is matter of binary code ready to run and that's it
sorry if the reply is not inharmonious, I really need to sleep :D, I hope that you get something from the reply
Thanks for your time
BR
Ahmed Essam
That was silly. You can look in .Net Framework source code and see what it is doing to set window text. And that's necessary.
Mr.Anonymous
First of all, what is the silly in your opinion? Second I think you should read enough to realize what we are talking about, Thanks for your time.
BR
Ahmed Essam
Just to know something every PM/Dev in MS (at least that's what we do in SQL Server, and I believe it's the same they do in .Net) put in mind when planning for performance, which is the use cases.
In other words, you used .Text to show your example, but in reality, who would be changing his application's window title 10000 times?
The reality that you can’t write every single line of code for performance or to be secure, you divide your features list into improvements, and then into use cases, for stuff that are not used that much, and for corner cases (like yours), we favor simplicity over completeness, and this is for many reasons, including ease of update, supportability, etc.
If you really want to test performance, you need to do it with stuff that people really expected to use that much, i.e. computations (addition, multiplications, etc), IO, threading, etc.
That's something you always need to put in mind when developing enterprise software (which has a totally different points of focus than consumer software), for example, Teradata DBMS is all about data warehousing, so they care about data retrieval speed more than anything else, that’s why their insert/update implementations sucks badly as it’s not their main business case, unlike Oracle and SQL Server who want to support OLTP as much as OLAP and data warehousing, and then they need to care about the insert/update operations as good as the data retrieval performance, so they must do some tradeoff performance between all those use cases.
Just don't base your whole opinion/judgment over a single operation which by design won't be implemented for performance :)
Actually I know exactly what do u mean, I wrote this post I was very angry :D because I have got a very bad experience specifically with the Compact framework.
The company I work for chose to do the application in C++ and pay 5 times of the cost than using the compact framework at that time, I think it was Windows Mobile 6 and Compact framework 2.0
Anyways, I think things is getting better and hardware is getting better, few years and I don't think the performance will be issue for business needs.
lots of things is getting better too, like software, design , the whole industry is getting stronger and wilder
Post a Comment