.NET 8 Datagrid Performance Benchmarks in FlexGrid for WinForms
Tags: webdev, devops, dotnet
Published: 2024-04-09 13:25:37

---
canonical_url: https://developer.mescius.com/blogs/net-8-datagrid-performance-benchmarks-in-flexgrid-for-winforms
description: Learn about updated performance benchmarks for our WinForms datagrid control in .NET 8. See more from ComponentOne today.
---
**What You Will Need**
- Visual Studio 2022
- ComponentOne WinForms Edition
- BenchmarkDotNet + [BenchmarkDotNet 0.13.12](https://www.nuget.org/packages/BenchmarkDotNet/)

**Controls Referenced**
- FlexGrid for WinForms + [C1.Win.FlexGrid 8.0.20233.636](https://www.nuget.org/packages/C1.Win.FlexGrid)
- [Documentation](https://developer.mescius.com/componentone/docs/win/online-flexgrid/overview.html)

**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 [<span>BenchmarkDotNet</span>](https://benchmarkdotnet.org/ "https://benchmarkdotnet.org/") 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, [<span>How to Compare Performance between .NET 5 and .NET Framework Controls</span>](https://developer.mescius.com/blogs/how-to-compare-performance-between-net5-and-net-framework-controls "https://developer.mescius.com/blogs/how-to-compare-performance-between-net5-and-net-framework-controls")<u>.</u>

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, [<span>ASP.NET</span>](http://asp.net/ "http://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();
```

Results:

![Results_1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3actv6dx6mvsz8hw0dzr.png)

![Paint FlexGrid .NET 8](//cdn.mescius.io/umb/media/k2woz2rl/benchmark_flexgrid_paint_net8.png)

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];

```
Results:

![Results_2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zclfq1zq3r6zscvthk1x.png)

![FlexGrid Assign Data .NET 8](//cdn.mescius.io/umb/media/gwmjeke3/benchmark_flexgrid_assigndata_net8.png)

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();
```

Results:

![Results_3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/suut3jqvjln4c03vvswr.png)

![FlexGrid Filter Columns .NET 8](//cdn.mescius.io/umb/media/rbzbrhje/benchmark_flexgrid_filtercolumns_net8.png)

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);
```

Results:

![Results_4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh6p96ym4u6r1ng4w5l5.png)

![FlexGrid Sort Column .NET 8](//cdn.mescius.io/umb/media/nlglqk4v/benchmark_flexgrid_sortcolumn_net8.png)

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)
    };
```

Results:

![Results_5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n66vniguqru2zn2x271r.png)

![FlexGrid Group Column .NET 8](//cdn.mescius.io/umb/media/2gold4zq/benchmark_flexgrid_groupcolumn_net8.png)

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();
```

Results:

![Results_6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgihjk0ijns10ir9set6.png)

![FlexGrid Autosize Columns .NET 8](//cdn.mescius.io/umb/media/t34dk4eb/benchmark_flexgrid_autosizecolumns_net8.png)

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](https://cdn.mescius.io/umb/media/rbzd5u0h/flexgridbenchmark8.zip) to test the benchmarks for yourself. Note that these tests can take a long time to run, so it’s advised to [<span>follow these tips</span>](https://benchmarkdotnet.org/articles/guides/good-practices.html "https://benchmarkdotnet.org/articles/guides/good-practices.html") 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 **
```

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