Cleanup.
This commit is contained in:
1 parent
0159042755
commit
ec69b1c406
38 files changed
+167
-181
No files matched your search
+6
-2
@@ -1,4 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
// Ignore Spelling: Poc
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using FluentAssertions;
|
||||
using Recyclable.CollectionsTests;
|
||||
|
||||
@@ -24,7 +26,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
_ = _list1.Should().ContainInConsecutiveOrder(_list2);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
if (_list1 is IDisposable disposable1)
|
||||
{
|
||||
@@ -35,6 +37,8 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
disposable2.Dispose();
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
// Ignore Spelling: Poc
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#pragma warning disable CA1822
|
||||
@@ -7,14 +9,14 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
public class LessOperatorVsAndOperatorBenchmarks
|
||||
{
|
||||
private const int bitShift = 1 << 31;
|
||||
private const int BitShift = 1 << 31;
|
||||
private static readonly Random _rnd = new(1);
|
||||
private static int num = -Math.Abs(_rnd.Next());
|
||||
private static int _num = -Math.Abs(_rnd.Next());
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
num = -1;
|
||||
Console.WriteLine($"*** We're comparing if {num} is < 0 ***");
|
||||
_num = -1;
|
||||
Console.WriteLine($"*** We're comparing if {_num} is < 0 ***");
|
||||
}
|
||||
|
||||
public void Cleanup() { }
|
||||
@@ -30,25 +32,25 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
[Benchmark(Baseline = true)]
|
||||
public void CompareWithLess()
|
||||
{
|
||||
DoNothing(num < 0);
|
||||
DoNothing(_num < 0);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void CompareWithAnd()
|
||||
{
|
||||
DoNothing((num & bitShift) != 0);
|
||||
DoNothing((_num & BitShift) != 0);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void CompareWithEqual()
|
||||
{
|
||||
DoNothing(num == -1);
|
||||
DoNothing(_num == -1);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void CompareToZero()
|
||||
{
|
||||
DoNothing(num == 0);
|
||||
DoNothing(_num == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
// Ignore Spelling: Poc
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
@@ -35,11 +37,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
|
||||
protected override Action GetTestMethod(RoundBenchmarkType benchmarkType) => benchmarkType switch
|
||||
{
|
||||
RoundBenchmarkType.MathFloor => RoundWithMathFloor,
|
||||
RoundBenchmarkType.MathRound => RoundWithMathRound,
|
||||
RoundBenchmarkType.WithTypecasting => RoundWithTypeCasting,
|
||||
_ => throw CreateUnknownBenchmarkTypeException(benchmarkType),
|
||||
};
|
||||
{
|
||||
RoundBenchmarkType.MathFloor => RoundWithMathFloor,
|
||||
RoundBenchmarkType.MathRound => RoundWithMathRound,
|
||||
RoundBenchmarkType.WithTypecasting => RoundWithTypeCasting,
|
||||
_ => throw CreateUnknownBenchmarkTypeException(benchmarkType),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
// Ignore Spelling: Poc
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
@@ -28,21 +30,21 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
public override SpanVsArrayBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
|
||||
|
||||
protected override Action GetTestMethod(SpanVsArrayBenchmarkType benchmarkType) => benchmarkType switch
|
||||
{
|
||||
SpanVsArrayBenchmarkType.ArrayGetWithVar => ArrayGetWithVar,
|
||||
SpanVsArrayBenchmarkType.ArrayGetWithField => ArrayGetWithField,
|
||||
SpanVsArrayBenchmarkType.SpanGet => SpanGet,
|
||||
SpanVsArrayBenchmarkType.ArraySetWithVar => ArraySetWithVar,
|
||||
SpanVsArrayBenchmarkType.ArraySetWithField => ArraySetWithField,
|
||||
SpanVsArrayBenchmarkType.SpanSet => SpanSet,
|
||||
_ => throw CreateUnknownBenchmarkTypeException(benchmarkType),
|
||||
};
|
||||
{
|
||||
SpanVsArrayBenchmarkType.ArrayGetWithVar => ArrayGetWithVar,
|
||||
SpanVsArrayBenchmarkType.ArrayGetWithField => ArrayGetWithField,
|
||||
SpanVsArrayBenchmarkType.SpanGet => SpanGet,
|
||||
SpanVsArrayBenchmarkType.ArraySetWithVar => ArraySetWithVar,
|
||||
SpanVsArrayBenchmarkType.ArraySetWithField => ArraySetWithField,
|
||||
SpanVsArrayBenchmarkType.SpanSet => SpanSet,
|
||||
_ => throw CreateUnknownBenchmarkTypeException(benchmarkType),
|
||||
};
|
||||
|
||||
public void ArrayGetWithVar()
|
||||
public void ArrayGetWithVar()
|
||||
{
|
||||
var data = TestObjects;
|
||||
var dataCount = TestObjectCount;
|
||||
for (long i = 0; i < dataCount; i++)
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
DoNothing(data[i]);
|
||||
}
|
||||
@@ -51,7 +53,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
public void ArrayGetWithField()
|
||||
{
|
||||
var dataCount = TestObjectCount;
|
||||
for (long i = 0; i < dataCount; i++)
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
DoNothing(_testObjects![i]);
|
||||
}
|
||||
@@ -60,7 +62,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
public void SpanGet()
|
||||
{
|
||||
var dataCount = TestObjectCount;
|
||||
Span<long> data = new(_testObjects, 0, dataCount);
|
||||
Span<int> data = new(_testObjects, 0, dataCount);
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
DoNothing(data[i]);
|
||||
@@ -71,7 +73,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
var data = TestObjects;
|
||||
var dataCount = TestObjectCount;
|
||||
for (long i = 0; i < dataCount; i++)
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
data[i] = i;
|
||||
}
|
||||
@@ -80,7 +82,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
public void ArraySetWithField()
|
||||
{
|
||||
var dataCount = TestObjectCount;
|
||||
for (long i = 0; i < dataCount; i++)
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
_testObjects![i] = i;
|
||||
}
|
||||
@@ -89,7 +91,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
public void SpanSet()
|
||||
{
|
||||
var dataCount = TestObjectCount;
|
||||
Span<long> data = new(_testObjects, 0, dataCount);
|
||||
Span<int> data = new(_testObjects, 0, dataCount);
|
||||
for (int i = 0; i < dataCount; i++)
|
||||
{
|
||||
data[i] = i;
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Sources;
|
||||
// Ignore Spelling: Poc
|
||||
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
|
||||
namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
public class TaskRunVsTaskFactoryStartNewBenchmarks
|
||||
{
|
||||
public class TaskRunVsTaskFactoryStartNewBenchmarks
|
||||
{
|
||||
public int NumberOfTasks = 100;
|
||||
private static readonly TaskFactory TaskPool = new();
|
||||
private static readonly TaskFactory _taskPool = new();
|
||||
|
||||
[Benchmark]
|
||||
public void OwnTaskFactory()
|
||||
{
|
||||
for (var i = 0; i < NumberOfTasks; i++)
|
||||
{
|
||||
_ = TaskPool.StartNew(() => {});
|
||||
_ = _taskPool.StartNew(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[Benchmark]
|
||||
public void TaskRun()
|
||||
{
|
||||
for (var i = 0; i < NumberOfTasks; i++)
|
||||
@@ -32,7 +28,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
[Benchmark(Baseline = true)]
|
||||
public void TaskFactoryStartNew()
|
||||
{
|
||||
for (var i = 0; i < NumberOfTasks; i++)
|
||||
@@ -59,5 +55,5 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
new Task(() => { }).Start(scheduler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user