Friday, May 9, 2008

C++/CLI vs C# (3)

1. Analyze the speed of calls from both managed languages to an unmanaged dll

Implemented a c++ dll that contains a function that has as parameter a structure like the following:
struct MyStruct
{
int SomeId;
double SomePrice;
}
extern "C" __declspec(dllexport) void PassStructIn(MyStruct* myStruct);

Implemented a C++/CLI application and also a C# application that make 150 millions calls to this function, passes a reference to the structure to the unmanaged code and have the values set in the unmanaged code.

The test results are the following:
C++/CLI 4140 milliseconds
C# 10890 milliseconds

It seems that the C++/CLI calls to unmanaged code is two time and a half faster than the C# ones.

There are many other possibilities to test but for this project this quick test is relevant for taking an architectural decision.

No comments: