DEV Community

Cover image for .NET 8 Datagrid Performance Benchmarks in FlexGrid for WinForms
Chelsea Devereaux for MESCIUS inc.

Posted on • Originally published at developer.mescius.com

.NET 8 Datagrid Performance Benchmarks in FlexGrid for WinForms

What You Will Need

Controls Referenced

Tutorial Concept
.NET 8 WinForms Datagrid Performance - This comparison will show the difference in performance for FlexGrid, a .NET datagrid control, across .NET version 6 and 8 in a WinForms application.


With the recent .NET 8 release, you may be wondering if the upgrade is worth the cost. In this blog, let’s look at the performance of our powerful WinForms datagrid control, FlexGrid, for .NET 8 compared to .NET 6.

.NET 8 Performance Improvements

.NET 8 uses the JIT (Just In Time) - compiler, similar to previous versions, but it now processes code faster and lessens the process execution time. The garbage collector performance has also improved by allowing you to dynamically adjust the memory limit - this is most useful for cloud solutions where you may need to scale the resources based on demand.

The biggest reason to upgrade your .NET applications is usually performance, but yet again, Microsoft is pushing the performance limitations with each version of .NET. This makes it the number one reason to migrate for any .NET platform.

How to Measure Performance in .NET 8

The popular BenchmarkDotNet tool can be used for straightforward performance measuring of your .NET code. Not only does it measure time and memory allocation, but you can also compare different versions of .NET along with different benchmark tests. You can also use parameters like number of rows and columns. It runs and outputs all the results in a single report.

You can read more about configuring the BenchmarkDotNet in our previous blog, How to Compare Performance between .NET 5 and .NET Framework Controls.

For the tests below, we’re testing FlexGrid for WinForms .NET 6 compared to .NET 8. These are long-term support versions. We’re generating data with 20 columns and a range of rows from 10,000 to 1 million. Let’s get to the results!

FlexGrid for .NET 8 Benchmark Results

FlexGrid is our powerful, cross-platform .NET datagrid, which is supported in WinForms, WPF, WinUI, UWP, Xamarin, ASP.NET Core, and even MAUI. The following benchmarks are performed for the WinForms FlexGrid.

  • Paint the Datagrid
  • Assign Data to the Datagrid
  • Filter Columns
  • Sort a Column
  • Group a Column
  • Autosize Columns

Benchmark: Paint the Datagrid

The paint benchmark measures the time and memory used to draw the control. This can invoked by the Refresh method.

    _flexGrid.Refresh();
Enter fullscreen mode Exit fullscreen mode

Results:

Results_1

Paint FlexGrid .NET 8

Observe that the drawing time and memory allocated are about the same regardless of the .NET version or number of rows. This is because the datagrid only draws the visible rows. The .NET 8 version is just 3-10% faster.

Benchmark: Assign Data to the Datagrid

This benchmark sets the datasource and a data-mapped column. The data is generated outside of the benchmark test.

    _flexGrid.DataSource = _data.DataTable;
    _flexGrid.Cols[columnIndex].DataMap = _data.DataMaps[dataMapIndex];

Enter fullscreen mode Exit fullscreen mode

Results:

Results_2

FlexGrid Assign Data .NET 8

Observe that more memory and time are used to assign larger data sources, but there’s not much difference between .NET 6 and .NET 8. The .NET 8 version is merely 2-13% faster.

Benchmark: Filter Columns

The filtering benchmark creates and applies two conditional filters using the following test code.

    _flexGrid.AllowFiltering = true;
    ConditionFilter conditionFilter = (_flexGrid.Cols[_flexGrid.Cols.Fixed].Filter as ColumnFilter).ConditionFilter;

    Condition condition1 = conditionFilter.Condition1;
    condition1.Operator = ConditionOperator.GreaterThan;
    condition1.Parameter = _condition1Parameter;

    Condition condition2 = conditionFilter.Condition2;
    condition2.Operator = ConditionOperator.LessThan;
    condition2.Parameter = _condition2Parameter;

    _flexGrid.ApplyFilters();
Enter fullscreen mode Exit fullscreen mode

Results:

Results_3

FlexGrid Filter Columns .NET 8

Observe the .NET 8 version is 15-21% faster!

Benchmark: Sort a Column

The sorting benchmark sorts a single column using the FlexGrid’s sort method.

    _flexGrid.Sort(SortFlags.Ascending, 1);
Enter fullscreen mode Exit fullscreen mode

Results:

Results_4

FlexGrid Sort Column .NET 8

Observe there’s no dramatic improvement between .NET 6 and .NET 8 for a million rows. However, the .NET 8 version is 4-11% faster for small and medium-sized data sources.

Benchmark: Group a Column

The grouping benchmark groups a single column by adding a group descriptor to the FlexGrid.

    _flexGrid.GroupDescriptions = new List<GroupDescription>()
    {
        new GroupDescription(_flexGrid.Cols[_firstDataMapColumnIndex].Name, ListSortDirection.Ascending)
    };
Enter fullscreen mode Exit fullscreen mode

Results:

Results_5

FlexGrid Group Column .NET 8

Observe that the larger the data source, the more time is gained with .NET 8. But with smaller data sets, there is a higher percentage of performance gains (31% with 10k rows compared to 18% for 1M rows)

Benchmark: Autosize Columns

Auto-sizing the columns to fit the contents is an expensive feature, but sometimes, it’s worth the performance cost. This benchmark uses a flat 10,000 rows measured against different column counts.

    _flexGrid.AutoSizeCols();
Enter fullscreen mode Exit fullscreen mode

Results:

Results_6

FlexGrid Autosize Columns .NET 8

Observe the .NET 8 version performs faster and has better memory allocation for this operation for all data source sizes. The improvement gains range from around 15 to 20%.

.NET 8 Benchmark Conclusion

While memory allocation is comparable between .NET 6 and .NET 8, these benchmarks demonstrate that .NET 8 offers faster run times to perform various datagrid operations:

  • Painting the datagrid is 3-10% faster
  • Assigning data is 2-13% faster
  • Filtering columns is 15-21% faster
  • Sorting a column is 4-11% faster
  • Grouping a column is 18-31% faster
  • Autosizing columns is 15-20% faster

Overall, .NET 8 is anywhere from 2 - 31% faster than .NET 6, depending on which feature you’re using and the size of your datasource.

How to Test the Benchmarks Yourself

Download the sample to test the benchmarks for yourself. Note that these tests can take a long time to run, so it’s advised to follow these tips before running them. The attached sample can be run using the following command in the Developer Command Prompt.

    dotnet run -c Release -f net6.0-windows --project FlexGridBenchmark8 --runtimes net6.0-windows net8.0-windows --filter **
Enter fullscreen mode Exit fullscreen mode

Also, you can fine-tune which tests run by either the command or by simply excluding various class files from the Benchmark folder.

Top comments (0)