no. the ms c++ compiler has an integrated intermediate code which is
optimized before converting/outputting it as the target code which may be
x96 or in this case msil. for example may loop unrolling, inlining and
common subexpression elimination done before outputting the msil code.
the jit compiler is (at least for now, not able to do all of these things).
You know what? Because you have read something or because you have some
"proof of evidence", that is, you have measured the performance differences?
The MC++ compiler generates the same IL as C# and other compilers, the JIT
is perfectly able to inline (restricted by a number of heuristics), loop
unroll and eliminate subexpressions. Note also the the MC++ compiler is dead
end, it has been superseded by the C++/CLI compiler in VS2005, which allows
some optimizations not done by C# (especially loops), but in general there
isn't any significant performance difference between both languages.
Don't know what you mean by X96, but I guess it's X86 you mean. While it's
true that MC++ can generate X86 when no IL can be generated, but the result
is an non verifiable assembly (unsafe in C# terms), that means it can only
run with full trust permissions.
Willy.
PS. Take a look at this article and dowload and run the accompanying code,
this might give you an idea how both relate, but please note that while such
kind of benchmarks tell you something, they don't tell the whole story,
there is much more to build performing applications, the language choice is
not directly one of them when talking managed code.
| no. the ms c++ compiler has an integrated intermediate code which is
| optimized before converting/outputting it as the target code which may be
[quoted text clipped - 22 lines]
| >> there
| >> already a tool which uses a similar approach?
cody - 18 Mar 2006 16:26 GMT
> C++/CLI compiler in VS2005, which allows
> some optimizations not done by C# (especially loops),
Thats exactly what I meant..
> but in general there
> isn't any significant performance difference between both languages.
I never said that it is somewhat significant. I've read an article about the
differences of generated MC++ vs. C# code some time ago but I couldn't find
it anymore.
> Don't know what you mean by X96, but I guess it's X86 you mean.
right.
> PS. Take a look at this article and dowload and run the accompanying code,
which article?
> this might give you an idea how both relate, but please note that while
> such
> kind of benchmarks tell you something, they don't tell the whole story,
> there is much more to build performing applications, the language choice
> is
> not directly one of them when talking managed code.
I never said that. I was just an idea how one could optimize an existing
C#/VB.NET assembly.
Willy Denoyette [MVP] - 18 Mar 2006 18:24 GMT
|> C++/CLI compiler in VS2005, which allows
| > some optimizations not done by C# (especially loops),
[quoted text clipped - 7 lines]
| differences of generated MC++ vs. C# code some time ago but I couldn't find
| it anymore.
I think you should not expect this from MC++, it has never been optimized
that way, take a look at C++/CLI, this is the compiler that has the most
optimizations available at the IL level, but be warned some my produce
unverifiable IL, so when compiled with /clr:safe or /clr:pure, you don't get
the same level of IL optimization.
| > Don't know what you mean by X96, but I guess it's X86 you mean.
|
[quoted text clipped - 3 lines]
|
| which article?
Sorry dropped on the floor I guess ;-)
http://www.grimes.demon.co.uk/dotnet/man_unman.htm
| > this might give you an idea how both relate, but please note that while
| > such
[quoted text clipped - 5 lines]
| I never said that. I was just an idea how one could optimize an existing
| C#/VB.NET assembly.
I have tried by hand tuning the IL produced by C#, in some cases this
resulted in an unverifiable assembly, in other cases the performance
advantage wasn't measurable and in some cases the result was a worse
performance level, even when producing shorter IL. The same thing happens
when compiling with /Ox in C++/CLI sometimes the resultant performance is
worse. So it's not that simple to produce better IL that also results in
better (and predictable) run-time performance.
Willy.
cody - 18 Mar 2006 16:34 GMT
> the JIT is perfectly able to inline (restricted by a number of
> heuristics),
> loop unroll and eliminate subexpressions.
I never said other, just that the jit doesn't always do ALL of these things
or not in the quality as it is done by MC++.
> Note also the the MC++ compiler is dead
> end, it has been superseded by the C++/CLI compiler in VS2005
I think this applies to both of them.
> C++/CLI compiler in VS2005, which allows
> some optimizations not done by C# (especially loops),
Thats exactly what I meant..
> but in general there
> isn't any significant performance difference between both languages.
I never said that it is somewhat significant. I've read an article about the
differences of generated MC++ vs. C# code some time ago but I couldn't find
it anymore.
> PS. Take a look at this article and dowload and run the accompanying code,
which article?
> this might give you an idea how both relate, but please note that while
> such
> kind of benchmarks tell you something, they don't tell the whole story,
> there is much more to build performing applications, the language choice
> is
> not directly one of them when talking managed code.
I never said that. I was just an idea how one could optimize an existing
C#/VB.NET assembly.
cody - 18 Mar 2006 16:34 GMT
> the JIT is perfectly able to inline (restricted by a number of
> heuristics),
> loop unroll and eliminate subexpressions.
I never said other, just that the jit doesn't always do ALL of these things
or not in the quality as it is done by MC++.
> Note also the the MC++ compiler is dead
> end, it has been superseded by the C++/CLI compiler in VS2005
I think this applies to both of them.
> C++/CLI compiler in VS2005, which allows
> some optimizations not done by C# (especially loops),
Thats exactly what I meant..
> but in general there
> isn't any significant performance difference between both languages.
I never said that it is somewhat significant. I've read an article about the
differences of generated MC++ vs. C# code some time ago but I couldn't find
it anymore.
> PS. Take a look at this article and dowload and run the accompanying code,
which article?
> this might give you an idea how both relate, but please note that while
> such
> kind of benchmarks tell you something, they don't tell the whole story,
> there is much more to build performing applications, the language choice
> is
> not directly one of them when talking managed code.
I never said that. I was just an idea how one could optimize an existing
C#/VB.NET assembly.
muga - 06 Apr 2006 00:13 GMT
I'm I missing something? Seems like VC++ .Net is faster! VC++ 6.0 is even
faster.
I'm currently writing a program for a particle simulator. I've aleady written
one in VC++ 6.0. Now I'm busy writing an updated version in Visual Studio
2005 C#. During my development phase I noticed that calculations aren't as
zippy as I thought. So, I went and wrote a little benchmark program to test
some 3d vector calculations.
In C# the code is:
--------------------------------------------------------------------
namespace Benchmark
{
class Program
{
static void Main(string[] args)
{
CVector position1 = new CVector(1, 2, 3);
CVector position2 = new CVector(4, 6, 7);
float x1 = 0, y1 = 0, z1 = 0;
float x2 = 0, y2 = 0, z2 = 0;
int loopCount = 90000000;
DateTime start = DateTime.Now;
float dist = 0;
for (int x = 0; x < loopCount; x++)
{
position1.x = x1;
position1.y = y1;
position1.z = z1;
position2.x = x2;
position2.y = y2;
position2.z = z2;
x1 += 1;
y1 += 2;
z1 += 3;
x2 += 3;
y2 += 4;
z2 += 5;
CVector lenvec = (position1 - position2);
dist += lenvec.Length() - 11.1f - 56.3f;
}
DateTime end = DateTime.Now;
Console.WriteLine("Time: "+ end.Subtract(start).ToString());
Console.WriteLine("Dist: " + dist.ToString());
Console.ReadLine();
}
}
}
...
public class CVector
{
...
public float Length()
{
float root = x*x + y*y + z*z;
if(root>0)
return (float)Math.Sqrt(root);
else
return 0;
}
...
}
In C++ the code is:
--------------------------------------------------------------------
#include "stdafx.h"
#include "vector.h"
using namespace System;
#include <iostream>
#include <string>
using namespace std;
int main(array<System::String ^> ^args)
{
float time=0;
float x1=0,y1=0,z1=0;
float x2=0,y2=0,z2=0;
int loopCount = 90000000;
DateTime start = DateTime::Now.Now;
float dist = 0;
for (int x = 0; x < loopCount; x++)
{
CVector position1 = CVector(x1, y1, z1);
CVector position2 = CVector(z2, y2, z2);
x1+=1;
y1+=2;
z1+=3;
x2+=3;
y2+=4;
z2+=5;
CVector lenvec = (position1 - position2);
dist += lenvec.Length() - 11.1f - 56.3f;
}
DateTime end = DateTime::Now.Now;
String ^ timelen = (end-start).ToString();
String ^ totaldist = dist.ToString();
Console::WriteLine(totaldist);
Console::WriteLine(timelen);
cin.get();
return 0;
}
...
class CVector
{
...
const float Length() const
{
float root = x*x + y*y + z*z;
if(root)
return (float)sqrt(root);
else
return 0;
}
...
Machine used:
1.5 GHz Pentium 4
Test results:
for Visual Studio 2005 C# Express with "Release" and "Optimize Code"
17.53 seconds
for Visual Studio 2005 C++ Express with "Release" and options /Ox /Ot
8.51 seconds (9 seconds faster!)
for Visual Studio 6.0 C++ Professional with "Release" and "Maximum Speed" -
Native Code (of course)
4.14 seconds! (Even Faster!)
All are tested on the same machine. Anyone, give me an explaination.
I also tested with Visual Studio 2005 Professional. Could not determine
anything to catch up with VC6.0.
Why should I develop a particle simulator in C#, or in C++ .Net?
Am I missing something? Please Help.