Skip to content

chore: Add benchmarks that use dedicated optimization path by System.Linq#110

Merged
neuecc merged 1 commit intoCysharp:mainfrom
filzrev:chore-add-compare-perf-benchmaks
Apr 4, 2025
Merged

chore: Add benchmarks that use dedicated optimization path by System.Linq#110
neuecc merged 1 commit intoCysharp:mainfrom
filzrev:chore-add-compare-perf-benchmaks

Conversation

@filzrev
Copy link
Copy Markdown
Contributor

@filzrev filzrev commented Apr 4, 2025

This PR add LINQ benchmarks that described at following URLs.

From benchmark results.
Some dedicated optimization path seems to be used by System.Linq.

Results of Net80OptimizedBenchmark

Method Mean Error StdDev Gen0 Allocated
SelectToList_SystemLinq 811.08 ns 426.81 ns 23.395 ns 0.9804 4.01 KB
RepeatToList_SystemLinq 58.63 ns 77.59 ns 4.253 ns 0.2658 1.09 KB
RangeSelectToList_SystemLinq 775.82 ns 715.34 ns 39.210 ns 1.0128 4.14 KB
SelectToList_ZLinq 2,997.08 ns 516.19 ns 28.294 ns 0.9804 4.01 KB
RepeatToList_ZLinq 2,452.75 ns 354.05 ns 19.407 ns 0.2632 1.09 KB
RangeSelectToList_ZLinq 2,772.41 ns 295.97 ns 16.223 ns 0.9995 4.09 KB
RangeSelectToList_ZLinqOptimized 2,471.54 ns 180.95 ns 9.918 ns 0.9918 4.05 KB

Results of Net90OptimizedBenchmark

Method Mean Error StdDev Gen0 Allocated
DistinctFirst_SystemLinq 16.095 ns 14.5952 ns 0.8000 ns 0.0153 64 B
AppendSelectLast_SystemLinq 29.764 ns 24.8648 ns 1.3629 ns 0.0268 112 B
RangeReverseCount_SystemLinq 18.115 ns 6.8303 ns 0.3744 ns 0.0115 48 B
DefaultIfEmptySelectElementAt_SystemLinq 15.344 ns 7.2214 ns 0.3958 ns 0.0115 48 B
ListSkipTakeElementAt_SystemLinq 32.375 ns 18.4966 ns 1.0139 ns 0.0229 96 B
RangeUnionFirst_SystemLinq 32.644 ns 25.5304 ns 1.3994 ns 0.0268 112 B
SelectWhereSelectSum_SystemLinq 3,282.915 ns 47.7935 ns 2.6197 ns 0.0381 168 B
ZDistinctFirst_ZLinq 43.233 ns 8.5557 ns 0.4690 ns 0.0134 56 B
ZAppendSelectLast_ZLinq 2,141.056 ns 282.5460 ns 15.4873 ns - -
ZRangeReverseCount_ZLinq 8.600 ns 0.1929 ns 0.0106 ns - -
ZDefaultIfEmptySelectElementAt_ZLinq 12.830 ns 12.8783 ns 0.7059 ns - -
ZListSkipTakeElementAt_ZLinq 20.908 ns 4.7675 ns 0.2613 ns - -
ZRangeUnionFirst_ZLinq 55.177 ns 17.0159 ns 0.9327 ns 0.0229 96 B
ZRangeUnionFirst_ZLinqOptimized 47.520 ns 10.3418 ns 0.5669 ns 0.0134 56 B
ZSelectWhereSelectSum_ZLinq 1,303.368 ns 84.3879 ns 4.6256 ns - -

@neuecc
Copy link
Copy Markdown
Member

neuecc commented Apr 4, 2025

Thank you.
Hmn... some things might be worse than I imagined.
I'll improve it.

@neuecc neuecc merged commit 3ae8bd5 into Cysharp:main Apr 4, 2025
4 checks passed
@neuecc
Copy link
Copy Markdown
Member

neuecc commented Apr 4, 2025

some ZLinq test is invalid benchmark.
This was causing extreme (far beyond what I had expected) performance degradation.

wrong

        _ = source.Select(i => i * 2)
                  .AsValueEnumerable()
                  .ToList();

right

        _ = source
                  .AsValueEnumerable()
                  .Select(i => i * 2)
                  .ToList();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants