forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify segmented list to grow by growth rate.
A growth rate of 2x matches the current code behavior. A growth rate of just over 1 matches the growth rate (1 segment) in the other PR (dotnet#75708). All growth rates benchmarked: 1.000001, 1.1, 1.25, 1.5, 2 Obviously, the single segment growth rate is a non-starter without allowing null segments (which is the approach the other PR took). The 2x rate matches current behavior, and is really only measured as a baseline. From my reading of this chart, it looks like 1.1 is the best of these choices.
- Loading branch information
Showing
3 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Tools/IdeCoreBenchmarks/SegmentedListBenchmarks_Add_SegmentCount.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.CodeAnalysis.Collections; | ||
using Microsoft.CodeAnalysis.Collections.Internal; | ||
|
||
[MemoryDiagnoser] | ||
public class SegmentedListBenchmarks_Add_SegmentCounts | ||
{ | ||
[Params(16, 256, 4096, 65536)] | ||
public int SegmentCount { get; set; } | ||
|
||
[ParamsAllValues] | ||
public bool AddExtraItem { get; set; } | ||
|
||
[Params(1.000001, 1.1, 1.25, 1.5, 2)] | ||
public double SegmentGrowthRate { get; set; } | ||
|
||
[Benchmark] | ||
public void AddObjectToList() | ||
=> AddToList(new object()); | ||
|
||
[Benchmark] | ||
public void AddLargeStructToList() | ||
=> AddToList(new LargeStruct()); | ||
|
||
[Benchmark] | ||
public void AddEnormousStructToList() | ||
=> AddToList(new EnormousStruct()); | ||
|
||
private void AddToList<T>(T item) | ||
{ | ||
SegmentedList<T>.SegmentGrowthRate = SegmentGrowthRate; | ||
|
||
var count = SegmentCount * SegmentedArrayHelper.GetSegmentSize<T>(); | ||
if (AddExtraItem) | ||
count++; | ||
|
||
var array = new SegmentedList<T>(); | ||
for (var i = 0; i < count; i++) | ||
array.Add(item); | ||
} | ||
|
||
private struct MediumStruct | ||
{ | ||
public int i1 { get; set; } | ||
public int i2 { get; set; } | ||
public int i3 { get; set; } | ||
public int i4 { get; set; } | ||
public int i5 { get; set; } | ||
} | ||
|
||
private struct LargeStruct | ||
{ | ||
public MediumStruct s1 { get; set; } | ||
public MediumStruct s2 { get; set; } | ||
public MediumStruct s3 { get; set; } | ||
public MediumStruct s4 { get; set; } | ||
} | ||
|
||
private struct EnormousStruct | ||
{ | ||
public LargeStruct s1 { get; set; } | ||
public LargeStruct s2 { get; set; } | ||
public LargeStruct s3 { get; set; } | ||
public LargeStruct s4 { get; set; } | ||
public LargeStruct s5 { get; set; } | ||
public LargeStruct s6 { get; set; } | ||
public LargeStruct s7 { get; set; } | ||
public LargeStruct s8 { get; set; } | ||
public LargeStruct s9 { get; set; } | ||
public LargeStruct s10 { get; set; } | ||
} | ||
} |