Discussion: WinUI Performance comparison between C# & C++
See original GitHub issueComparing the performance in WinUI to create component
Discussion: WinUI Performance comparison between C# & C++
While comparing the simple “for loop” between C# and C++ there is vast difference in performance.
For Eg:
WinUI C# for loop
List<string> stringCollection = new List<string>(); for (int i = 0; i < 100000; i++) { stringCollection.Add("item"); }
or foreach loop
foreach (var item in stringCollection) { }
took 0.002 sec
but in WinUI C++
IVector<hstring> stringCollection= winrt::single_threaded_vector<hstring>(); for (int i = 0; i < 100000; i++) { stringCollection.Append(L"item"); }
or
for (auto item : stringCollection) { }
took 0.2395 sec (IVector or IObservableVector have same performance.)
It looks C++ performance is low compared to C#. So, which one will be good choice for creating component in WinUI based on performance and memory consumption.
Related Links
https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/collections
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
As @sylveon pointed out, this is not a meaningful comparison. And as @riverar notes, this has nothing to do with WinUI. If you gave both C# and C++ a WinRT
IVector<hstring>
you will find that the C++ version outperforms the C# version by a very considerable margin. I wrote about this a few years back.But here you’re comparing a native C# list with a COM interface. The C# version will obviously outperform the C++ example because the C# version is inlined whereas the COM interface can never be inlined (no matter the language). A better comparison would be a C#
List
and C++std::vector
.If you are looking for the best possible performance for COM/WinRT/WinUI, C++ outperforms C# every time.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.