forked from dotnet/corefx
-
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.
- Loading branch information
Pär Björklund
committed
Aug 4, 2017
1 parent
152b2c1
commit 7ef44ae
Showing
8 changed files
with
150 additions
and
19 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
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
46 changes: 46 additions & 0 deletions
46
src/System.Net.Primitives/tests/FunctionalTests/IPAddressSpanTest.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,46 @@ | ||
// 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 System.Collections.Generic; | ||
using System.Net.Sockets; | ||
|
||
using Xunit; | ||
|
||
namespace System.Net.Primitives.Functional.Tests | ||
{ | ||
public static class IPAddressSpanTest | ||
{ | ||
private const long MinAddress = 0; | ||
private const long MaxAddress = 0xFFFFFFFF; | ||
|
||
private const long MinScopeId = 0; | ||
private const long MaxScopeId = 0xFFFFFFFF; | ||
|
||
private static byte[] ipV6AddressBytes1 = new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; | ||
private static byte[] ipV6AddressBytes2 = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; | ||
|
||
private static IPAddress IPV6Address1() | ||
{ | ||
return new IPAddress(ipV6AddressBytes1); | ||
} | ||
|
||
private static IPAddress IPV6Address2() | ||
{ | ||
return new IPAddress(ipV6AddressBytes2); | ||
} | ||
|
||
[Theory] | ||
[InlineData(new object[] { new byte[] { 0x8f, 0x18, 0x14, 0x24 } })] | ||
[InlineData(new object[] { new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 } })] | ||
public static void TryWriteBytes_RightSizeBuffer_Success(byte[] address) | ||
{ | ||
var result = new byte[address.Length]; | ||
int bytesWritten = -1; | ||
IPAddress ip = new IPAddress(address); | ||
Assert.Equal(true, ip.TryWriteBytes(new Span<byte>(result), out bytesWritten)); | ||
Assert.Equal(address, result); | ||
Assert.Equal(address.Length, bytesWritten); | ||
} | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/System.Net.Primitives/tests/PerformanceTests/IPAddressPerformanceTests.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,47 @@ | ||
// 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 Microsoft.Xunit.Performance; | ||
using Xunit; | ||
|
||
namespace System.Net.Primitives.Tests | ||
{ | ||
public static class IPAddressPerformanceTests | ||
{ | ||
[Benchmark] | ||
[MeasureGCCounts] | ||
[InlineData(new object[] { new byte[] { 0x8f, 0x18, 0x14, 0x24 } })] | ||
[InlineData(new object[] { new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 } })] | ||
public static void TryWriteBytes(byte[] address) | ||
{ | ||
var ip = new IPAddress(address); | ||
var bytes = new byte[address.Length]; | ||
var bytesSpan = new Span<byte>(bytes); | ||
int bytesWritten = 0; | ||
foreach (var iteration in Benchmark.Iterations) | ||
{ | ||
using (iteration.StartMeasurement()) | ||
{ | ||
ip.TryWriteBytes(bytesSpan, bytesWritten); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
[MeasureGCCounts] | ||
[InlineData(new object[] { new byte[] { 0x8f, 0x18, 0x14, 0x24 } })] | ||
[InlineData(new object[] { new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 } })] | ||
public static void GetAddressBytes(byte[] address) | ||
{ | ||
var ip = new IPAddress(address); | ||
foreach (var iteration in Benchmark.Iterations) | ||
{ | ||
using (iteration.StartMeasurement()) | ||
{ | ||
var bytes = ip.GetAddressBytes(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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