Skip to content

Commit f13a26f

Browse files
author
Oren (electricessence)
committed
Non essential inspection and benchmark tuneup.
1 parent b58c310 commit f13a26f

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

benchmarking/Benchmark.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using Open.Diagnostics;
22
using System;
33
using System.Collections.Generic;
4-
using System.Diagnostics;
4+
using System.Diagnostics.CodeAnalysis;
55
using System.Threading.Tasks;
66

7+
#if DEBUG
8+
using System.Diagnostics;
9+
#endif
10+
711
namespace Open.Disposable.ObjectPools
812
{
13+
[SuppressMessage("ReSharper", "AccessToDisposedClosure")]
914
public class Benchmark<T> : BenchmarkBase<Func<IObjectPool<T>>>
1015
where T : class
1116
{
@@ -23,17 +28,20 @@ protected override IEnumerable<TimedResult> TestOnceInternal()
2328
{
2429
using (var pool = Param())
2530
{
26-
31+
if (pool == null) throw new NullReferenceException();
2732
//yield return TimedResult.Measure("Take From Empty (In Parallel)", () =>
2833
//{
2934
// Parallel.For(0, TestSize, i => _items[i] = pool.Take());
3035
//});
3136

3237
yield return TimedResult.Measure("Give To (In Parallel)", () =>
3338
{
39+
// ReSharper disable once AccessToDisposedClosure
3440
Parallel.For(0, TestSize, i => pool.Give(_items[i]));
41+
#if DEBUG
3542
var count = pool.Count;
3643
Debug.Assert(pool is OptimisticArrayObjectPool<T> || count == TestSize, $"Expected {TestSize}, acutal count: {count}");
44+
#endif
3745
});
3846

3947
yield return TimedResult.Measure("Mixed 90%-Take/10%-Give (In Parallel)", () =>

benchmarking/ConsoleReport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Open.Disposable.ObjectPools
66
{
7-
public class ConsoleReport<T> : Open.Diagnostics.BenchmarkConsoleReport<Func<IObjectPool<T>>>
7+
public class ConsoleReport<T> : Diagnostics.BenchmarkConsoleReport<Func<IObjectPool<T>>>
88
where T : class
99
{
1010
const int ITERATIONS = 100000;
11-
public ConsoleReport(TextWriter output = null) : base(ITERATIONS, output, (c, r, p) => Benchmark<T>.Results(c, r, p))
11+
public ConsoleReport(TextWriter output = null) : base(ITERATIONS, output, Benchmark<T>.Results)
1212
{
1313
}
1414

benchmarking/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using Open.Disposable.ObjectPools;
33
using Open.Text.CSV;
44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.IO;
67
using System.Text;
78

89
class Program
910
{
10-
static void Main(string[] args)
11+
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
12+
static void Main()
1113
{
1214
Console.Write("Initializing...");
1315

source/IObjectPool.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34

45
namespace Open.Disposable
56
{
7+
[SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")]
68
public interface IObjectPool<T> : IDisposable
79
where T : class
810
{

tests/Open.Disposable.ObjectPools.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<RootNamespace>Open.Disposable</RootNamespace>
66
</PropertyGroup>
77

0 commit comments

Comments
 (0)