Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Derive OrderedEnumerable from Iterator#98874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@stephentoub
Copy link
Member

The OrderedEnumerable implementation today doesn't derive from Iterator, and it has a GetEnumerator method implemented with yield. That means the optimization that allows the enumerable to be reused as the enumerator doesn't kick in, and we end up allocating a separate enumerator object in order to iterate through an Order{By} enumerable.

MethodToolchainLengthMeanRatioAllocatedAlloc Ratio
Order\main\corerun.exe251.61 ns1.00112 B1.00
Order\pr\corerun.exe246.16 ns0.9088 B0.79
OrderBy\main\corerun.exe286.11 ns1.00328 B1.00
OrderBy\pr\corerun.exe287.89 ns1.02304 B0.93
Order\main\corerun.exe100652.72 ns1.00504 B1.00
Order\pr\corerun.exe100580.34 ns0.89480 B0.95
OrderBy\main\corerun.exe1001,982.54 ns1.001504 B1.00
OrderBy\pr\corerun.exe1001,989.22 ns1.001480 B0.98
usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);[MemoryDiagnoser(false)][HideColumns("Job","Error","StdDev","Median","RatioSD")]publicpartialclassTests{privateint[]_ints;privatePerson[]_people;[Params(2,100)]publicintLength{get;set;}[GlobalSetup]publicvoidSetup(){_ints=Enumerable.Range(0,Length).Reverse().ToArray();_people=_ints.Select(i=>newPerson{Age=i}).ToArray();}[Benchmark]publicintOrder(){intsum=0;foreach(intiin_ints.Order())sum+=i;returnsum;}[Benchmark]publicintOrderBy(){intsum=0;foreach(Personpin_people.OrderBy(p=>p.Age))sum+=p.Age;returnsum;}publicstructPerson{publicintAge{get;set;}}}

The OrderedEnumerable implementation today doesn't derive from Iterator, and it has a GetEnumerator method implemented with yield. That means the optimization that allows the enumerable to be reused as the enumerator doesn't kick in, and we end up allocating a separate enumerator object in order to iterate through an Order{By} enumerable.
@ghost
Copy link

Tagging subscribers to this area: @dotnet/area-system-linq
See info inarea-owners.md if you want to be subscribed.

Issue Details

The OrderedEnumerable implementation today doesn't derive from Iterator, and it has a GetEnumerator method implemented with yield. That means the optimization that allows the enumerable to be reused as the enumerator doesn't kick in, and we end up allocating a separate enumerator object in order to iterate through an Order{By} enumerable.

MethodToolchainLengthMeanRatioAllocatedAlloc Ratio
Order\main\corerun.exe251.61 ns1.00112 B1.00
Order\pr\corerun.exe246.16 ns0.9088 B0.79
OrderBy\main\corerun.exe286.11 ns1.00328 B1.00
OrderBy\pr\corerun.exe287.89 ns1.02304 B0.93
Order\main\corerun.exe100652.72 ns1.00504 B1.00
Order\pr\corerun.exe100580.34 ns0.89480 B0.95
OrderBy\main\corerun.exe1001,982.54 ns1.001504 B1.00
OrderBy\pr\corerun.exe1001,989.22 ns1.001480 B0.98
usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);[MemoryDiagnoser(false)][HideColumns("Job","Error","StdDev","Median","RatioSD")]publicpartialclassTests{privateint[]_ints;privatePerson[]_people;[Params(2,100)]publicintLength{get;set;}[GlobalSetup]publicvoidSetup(){_ints=Enumerable.Range(0,Length).Reverse().ToArray();_people=_ints.Select(i=>newPerson{Age=i}).ToArray();}[Benchmark]publicintOrder(){intsum=0;foreach(intiin_ints.Order())sum+=i;returnsum;}[Benchmark]publicintOrderBy(){intsum=0;foreach(Personpin_people.OrderBy(p=>p.Age))sum+=p.Age;returnsum;}publicstructPerson{publicintAge{get;set;}}}
Author:stephentoub
Assignees:-
Labels:

area-System.Linq

Milestone:9.0.0

@stephentoubstephentoub merged commit99a7964 intodotnet:mainFeb 24, 2024
@stephentoubstephentoub deleted the orderedenumerableiterator branchFebruary 24, 2024 01:42
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 25, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@eiriktsarpaliseiriktsarpaliseiriktsarpalis approved these changes

Assignees

@stephentoubstephentoub

Projects

None yet

Milestone

9.0.0

Development

Successfully merging this pull request may close these issues.

2 participants

@stephentoub@eiriktsarpalis

[8]ページ先頭

©2009-2025 Movatter.jp