Click to See Complete Forum and Search --> : Language/Platform Performance
TheCPUWizard
July 9th, 2008, 09:20 PM
Recently there have been a number of threads in various areas of Code Guru discussing the levels of performance in various languages and platforms.
As expected, the largest part of the discussion has revolved around .NET vs. "(anything)".
To help sort this out I have started to put together information on performance that will soon be published.
This information is currently available as:
http://www.dynconcepts.com/Benchmarks/DotNet_Performance_Part_I.htm
with the source at:
http://www.dynconcepts.com/Benchmarks/Benchmarks-20080709.zip
THIS IS VERY PRELIMINARY INFORMATION
My next task will be to delve into the differences found in these simple tests, and then add additional comparisions of increasing complexity.
People are encouraged to download this information, and look at the actual implementations. Suggestions and comments can be posted on this thread until such time as the material is published officially.
Hermit
July 12th, 2008, 06:41 PM
I think the introduction says it all, but the numbers definitely help drive the point.
What I'm getting out of this so far is:
- That allocation on the managed heap is indeed very fast, HOWEVER subtle changes in the way you interact with that memory can have a not-so-subtle effect on the GC's performance. So, I guess the paradigm shift you're referring to is that the mantra is no longer "avoid the heap, for it is slow"... it is a list of caveats that can drastically alter the way we write code. Finalizers are pretty easy to avoid, so perhaps it's not the best example of this shift, but it's an example nonetheless.
- I was very surprised that in the double-precision math test, C++ beat out C# more than ten-fold. I think that deserves further investigation, because it's a little hard to believe.
I'll try to give the code for these benchmarks a better look, as well as experiment with some additional tests of my own creation. As a final note, I hope this doesn't invite more of this "my language of choice is better than yours" garbage that's been going on.
TheCPUWizard
July 12th, 2008, 07:07 PM
Thanks for the comments. :wave: :wave: :wave:
You are right about the heap, and the effect of finalizers. Now consider that (nearly) every class that implements IDisposable has a finalizer (which is suppressed if you call Dispose()). Yet a survey of code (written by professional developers) show over 50% of disposable objects are not properly disposed....
The are a number of "suprises" that arise. The numbers of the for loop are one.
Regarding the double precision math, let me just say for now that C# is NOT inherently slower, but there ARE significant differences in how things are done....
Hopefully I will finish "Part I" before Monday. Right now I am working on creating a reproducable (simple) test case for one specific condition....
Please stay tuned....
Hermit
July 13th, 2008, 07:48 PM
Regarding the double precision math, let me just say for now that C# is NOT inherently slower,
That appears to be true. One thing I noticed was that the optimized C++ took advantage of the fact that most of the arithmetic in the loop only needed to be evaluated once, while the C# version did not (not in the generated IL at least). But that did not account for much of the performance difference. Apparently, the real slowdown for C# came from accessing member variables. Ignoring the fact that we're doing with a loop what could be done with a single multiplication, the following "optimized" version of the double math test yields interesting results:
double temp1 = (a * b) / (c - d);
double temp2 = Result;
for (int i = 0; i < 1000000; ++i)
{
temp2 += temp1;
}
Result = temp2;
The C++ version ran 15,590 times in 30 seconds, while the C# version ran 15,527 times... so, nearly identical. The important thing here is not that most of the math is displaced from the loop, but that only locals are accessed within the loop body. Incrementing Result in the loop rather than a tempory variable, for example, does not yield results remarkably different from the original test.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.