Skip to content

chore: Add consume extensions for ValueEnumerable#57

Merged
neuecc merged 2 commits intoCysharp:mainfrom
filzrev:chore-add-consume-extensions
Mar 22, 2025
Merged

chore: Add consume extensions for ValueEnumerable#57
neuecc merged 2 commits intoCysharp:mainfrom
filzrev:chore-add-consume-extensions

Conversation

@filzrev
Copy link
Copy Markdown
Contributor

@filzrev filzrev commented Mar 22, 2025

BenchmarkDotNet provider Consume extension methods for IEnumerable/IQueryable.
https://benchmarkdotnet.org/articles/samples/IntroDeferredExecution.html

This PR add Consume extension method for ValueEnumerable.

Other Changes

  • Add [Benchmark(Baseline = true)] to show Ratio/AllocRatio column
  • Remove some unused code

Benchmark results of LinqSelect4
Following results show original version of LinqSelect4 benchmark results.

Method Mean Error StdDev Ratio RatioSD Allocated Alloc Ratio
LinqSelect1 2,271.1 us 1,231.48 us 67.50 us 1.00 0.04 50 B 1.00
LinqSelect2 2,319.7 us 252.92 us 13.86 us 1.02 0.03 194 B 3.88
LinqSelect3 5,309.0 us 788.27 us 43.21 us 2.34 0.06 339 B 6.78
LinqSelect4 8,851.8 us 215.24 us 11.80 us 3.90 0.10 486 B 9.72
ZLinqSelect1 548.1 us 92.89 us 5.09 us 1.00 0.01 - NA
ZLinqSelect2 848.3 us 403.00 us 22.09 us 1.55 0.04 - NA
ZLinqSelect3 1,114.4 us 141.39 us 7.75 us 2.03 0.02 - NA
ZLinqSelect4 1,322.1 us 257.35 us 14.11 us 2.41 0.03 - NA

Benchmark results of LinqSelect4_Consume
Following results show consume version of LinqSelect4 benchmark results.
There is a roughly similar trend.
But ZLinqSelect1 seems slightly slower.

Method Mean Error StdDev Ratio RatioSD Allocated Alloc Ratio
LinqSelect1 2,306.2 us 1,060.19 us 58.11 us 1.00 0.03 51 B 1.00
LinqSelect2 2,360.9 us 185.45 us 10.16 us 1.02 0.02 194 B 3.80
LinqSelect3 5,374.4 us 958.46 us 52.54 us 2.33 0.05 339 B 6.65
LinqSelect4 8,906.6 us 1,205.41 us 66.07 us 3.86 0.09 486 B 9.53
ZLinqSelect1 817.8 us 62.56 us 3.43 us 1.00 0.01 - NA
ZLinqSelect2 948.5 us 133.55 us 7.32 us 1.16 0.01 - NA
ZLinqSelect3 1,194.9 us 332.23 us 18.21 us 1.46 0.02 - NA
ZLinqSelect4 1,433.6 us 65.81 us 3.61 us 1.75 0.01 - NA

@neuecc
Copy link
Copy Markdown
Member

neuecc commented Mar 22, 2025

Thank you, all of this is helpful (I wasn't familiar with Consume).
With the major rewrite in #56, benchmark results might change significantly.
When I tested locally, Order was still underperforming.
This seems largely because dotnet uses QuickSelect, which even omits part of the sorting process itself.

@neuecc neuecc merged commit 3ac19bb into Cysharp:main Mar 22, 2025
1 check passed
@neuecc
Copy link
Copy Markdown
Member

neuecc commented Mar 22, 2025

implemented QuickSelect; wins completely.
image

@filzrev filzrev deleted the chore-add-consume-extensions branch March 22, 2025 14:47
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