I have a question regarding C ++ / CLI vs Native C ++ speeds. I wrote a small test application, and I see very amazing results.
Unmanaged C ++ / CLI code seems to be significantly slower. Basically, I created two console applications. One standard win32 console application and CLR console application.
Here is the code I made for the test. I saved the code exactly the same in all versions of the test.
const int NumberOfTests = 10000000;
void GrowBalance(int numberOfYears)
{
std::cout<<"Called"<<std::endl;
DWORD startTime = GetTickCount();
int numberOfRandom = 0;
for(int i = 0; i < NumberOfTests; i++)
{
double dBalance = 10000.0;
for(int year = 0; year < numberOfYears; year++)
{
dBalance *= 1.05;
if(dBalance > 20000.00 && dBalance < 22000.00)
{
numberOfRandom++;
}
}
}
DWORD endTime = GetTickCount();
std::cout<<"Time Elapsed: "<<endTime - startTime<<std::endl;
std::cout<<"Number of random: "<<numberOfRandom<<std::endl;
}
Managed Output Code:
Called
Time Elapsed: 9937
Number of random: 20000000
Output managed code with controlled pragma (push, off):
Called
Time Elapsed: 24516
Number of random: 20000000
Enter your own code:
Called
Time Elapsed: 2156
Number of random: 20000000
GrowBalance 90 . . -, , , 4,5 , ++/CLI. , . , , , ++, . .
Update:
visual studio 2005 2008 . ++.
# 2:
. ~ 5000
2005 . 1875 . , 2005 CLI. - , .