Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Span: Add BinarySearch(...) extension methods for ReadOnlySpan<T> (and Span<T>) #25777

Merged
merged 32 commits into from
Dec 13, 2017
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d4f644a
S.M: Add initial BinarySearch span extensions method definitions.
nietras Nov 29, 2017
0d76e79
Add dummy xml comments to allow compiling. Add empty test files.
nietras Dec 4, 2017
9fb189f
Add to ref.
nietras Dec 4, 2017
9b5ad5b
Uncomment in test since extension method not found.
nietras Dec 4, 2017
8b4a8ba
Add initial implementation.
nietras Dec 7, 2017
cd7e6a7
Add more comments and string test.
nietras Dec 7, 2017
039349c
Add more tests.
nietras Dec 7, 2017
3d0ac20
Fix string test, add double tests.
nietras Dec 7, 2017
b84fad2
cleanup
nietras Dec 7, 2017
dc79fad
Remove empty check, and add empty tests.
nietras Dec 7, 2017
88c8e0b
Remove xml doc on exception, since that case is not applicable here.
nietras Dec 7, 2017
d86b248
Remove try/catch, and SR text etc.
nietras Dec 7, 2017
0a8a9c2
minor cleanup
nietras Dec 7, 2017
471f1f7
refactor tests.
nietras Dec 7, 2017
d953a2c
remove redundant.
nietras Dec 7, 2017
a31def9
merge master
nietras Dec 7, 2017
4327a5f
refactor string tests.
nietras Dec 7, 2017
9a19658
refactor tests, add comparer tests.
nietras Dec 7, 2017
c68312e
add icomparable overload tests.
nietras Dec 7, 2017
41ebc1c
Add test for int.MaxValue size span and possible overflow.
nietras Dec 7, 2017
42c5dec
compute median without subtract
nietras Dec 7, 2017
1e3b969
make generic params 'in'
nietras Dec 7, 2017
74f0496
Remove 'in' and update xml comments.
nietras Dec 8, 2017
5ce195e
add a few more test
nietras Dec 8, 2017
6d75e2a
add null throw tests
nietras Dec 8, 2017
90f3525
simplify max length no overflow test
nietras Dec 8, 2017
955bc4b
add basic perf tests.
nietras Dec 9, 2017
ee9830f
fix remaining review issues.
nietras Dec 9, 2017
cedb211
use InnerCount
nietras Dec 11, 2017
0b3ccec
use InnerCount
nietras Dec 11, 2017
dc60908
fix string perf test
nietras Dec 13, 2017
67a5965
fix MiddleIndex perf tests
nietras Dec 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/System.Memory/tests/Performance/Perf.Span.BinarySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace System.Memory.Tests
public class Perf_Span_BinarySearch
{
private const int InnerCount = 100000;
private const string NumberFormat = "D9";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain why this is needed?


[Benchmark(InnerIterationCount = InnerCount)]
[InlineData(1)]
Expand Down Expand Up @@ -69,7 +70,7 @@ public void SpanBinarySearch_Int_NotFoundAfter(int size)
[InlineData(1000)]
public void SpanBinarySearch_String_FirstIndex(int size)
{
BenchmarkAndAssert(size, 0.ToString(), 0);
BenchmarkAndAssert(size, 0.ToString(NumberFormat), 0);
}

[Benchmark(InnerIterationCount = InnerCount)]
Expand All @@ -79,7 +80,7 @@ public void SpanBinarySearch_String_FirstIndex(int size)
[InlineData(1000)]
public void SpanBinarySearch_String_MiddleIndex(int size)
{
BenchmarkAndAssert(size, (size / 2).ToString(), size / 2);
BenchmarkAndAssert(size, (size / 2).ToString(NumberFormat), size / 2);
}

[Benchmark(InnerIterationCount = InnerCount)]
Expand All @@ -89,7 +90,7 @@ public void SpanBinarySearch_String_MiddleIndex(int size)
[InlineData(1000)]
public void SpanBinarySearch_String_LastIndex(int size)
{
BenchmarkAndAssert(size, (size - 1).ToString(), size - 1);
BenchmarkAndAssert(size, (size - 1).ToString(NumberFormat), size - 1);
}

[Benchmark(InnerIterationCount = InnerCount)]
Expand All @@ -99,7 +100,8 @@ public void SpanBinarySearch_String_LastIndex(int size)
[InlineData(1000)]
public void SpanBinarySearch_String_NotFoundBefore(int size)
{
BenchmarkAndAssert(size, (-1).ToString(), -1);
// "/" is just before zero in character table
BenchmarkAndAssert(size, "/", -1);
}

[Benchmark(InnerIterationCount = InnerCount)]
Expand All @@ -109,7 +111,7 @@ public void SpanBinarySearch_String_NotFoundBefore(int size)
[InlineData(1000)]
public void SpanBinarySearch_String_NotFoundAfter(int size)
{
BenchmarkAndAssert(size, (size).ToString(), ~size);
BenchmarkAndAssert(size, (size).ToString(NumberFormat), ~size);
}

private static void BenchmarkAndAssert(int size, int value, int expectedIndex)
Expand Down Expand Up @@ -139,7 +141,7 @@ private static void BenchmarkAndAssert(int size, string value, int expectedIndex
Span<string> span = new string[size];
for (int i = 0; i < span.Length; i++)
{
span[i] = i.ToString();
span[i] = i.ToString(NumberFormat);
}

int index = 0;
Expand Down