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
[Config(typeof(PreviewVs20Config))] | |
public unsafe class LoopWithExit | |
{ | |
public int length = 100; | |
private string test1; | |
private string test2; | |
[Setup] | |
public void Setup() |
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
using System; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Diagnosers; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Running; | |
using BenchmarkDotNet.Toolchains.CsProj; | |
using BenchmarkDotNet.Toolchains.DotNetCli; |
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
// Improved by 14% | |
static byte TestIndexer5(Span<byte> data, out int z) | |
{ | |
byte x = 0; | |
z = -1; | |
// Write to z here should not be able to modify | |
// the span. | |
for (var idx = 0; idx < data.Length; idx++) | |
{ |
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
// Improved by 19% | |
static byte TestIndexer1(Span<byte> data) | |
{ | |
int length = data.Length; | |
byte x = 0; | |
for (var idx = 0; idx < length; idx++) | |
{ | |
x ^= data[idx]; // <---- bounds check here removed | |
} |
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
// Improved by 18% | |
static byte TestKnownSizeArray(int innerIterationCount) | |
{ | |
byte[] a = new byte[1024]; | |
SetData(a); | |
Span<byte> data = new Span<byte>(a); | |
byte x = 0; | |
for (int i = 0; i < innerIterationCount; i++) | |
{ |
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
using System; | |
using System.Diagnostics; | |
class InvariantExample | |
{ | |
int LoadLengths(int[] a, ref int[] b, Action doThings) | |
{ | |
int a_len = a.Length; | |
int b_len = b.Length; |
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
static byte TestIndexer1(Span<byte> data) | |
{ | |
int length = data.Length; | |
byte x = 0; | |
for (var idx = 0; idx < length; idx++) | |
{ | |
x ^= data[idx]; // Bounds check here now completely removed | |
} |
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
static byte TestKnownSizeArray(int innerIterationCount) | |
{ | |
byte[] a = new byte[1024]; | |
SetData(a); | |
Span<byte> data = new Span<byte>(a); | |
byte x = 0; | |
for (int i = 0; i < innerIterationCount; i++) | |
{ |
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
static byte TestKnownSizeCtor2(byte[] a, int innerIterationCount) | |
{ | |
Span<byte> data1 = new Span<byte>(a, 0, 512); | |
Span<byte> data2 = new Span<byte>(a, 512, 512); | |
byte x = 0; | |
for (int i = 0; i < innerIterationCount; i++) | |
{ | |
x = 0; |
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
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<packageSources> | |
<add key="dotnet core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" /> | |
<add key="appveyor-bdn" value="https://ci.appveyor.com/nuget/benchmarkdotnet" /> | |
</packageSources> | |
</configuration> |
NewerOlder