question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: WinUI Performance comparison between C# & C++

See original GitHub issue

Comparing 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:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
kennykerrcommented, Jul 13, 2020

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.

0reactions
github-actions[bot]commented, Jul 28, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is WinUI really production ready? : r/dotnet
Yes. The main bottleneck of WinUI3 is its performance issues in my opinion. WinUI 3 is used by every MAUI app and I...
Read more >
WinUI 3.0 vs WPF : r/dotnet
Here is a comparison table between WinUI 3, UWP, WPF, WinForms, MFC by Microsoft that might help with OP's question: ...
Read more >
Learn WinUI 3.0
A beginner's guide to building Windows applications with WinUI for UWP and ... WinUI compared to other Windows development frameworks · Summary ·...
Read more >
#19352: Modernize wxMSW with WinUI
I dont see why it is not a valid comparison... If you cannot tell a difference between a child control (Microsoft.UI.Xaml.Controls.ColorPicker) and a...
Read more >
Comparing WinUI and Its Predecessors | ComponentOne
Explore the differences developers encounter between WinUI and other Microsoft GUI frameworks. See more from ComponentOne today.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found