RecyclableArrayList performance improvements.
This commit is contained in:
1 parent
012fc3b21f
commit
4aa32a32f7
7 files changed
+134
-47
No files matched your search
@@ -4,9 +4,10 @@ using Recyclable.Collections.Benchmarks;
|
||||
//BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(new[] { "-f*" });
|
||||
|
||||
BenchmarkRunner.Run<RecyclableCollectionsBenchmarks>();
|
||||
//BenchmarkRunner.Run<RefVsInstanceMemberBenchmarks>();
|
||||
|
||||
//var benchmark = new RecyclableCollectionsBenchmarks();
|
||||
//benchmark.RecyclableArrayList_Add();
|
||||
//benchmark.RecyclableArrayList_AddRange_WithCapacity();
|
||||
//benchmark.RecyclableArrayList_Add_WithCapacity();
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void List_Add()
|
||||
{
|
||||
var data = TestObjects;
|
||||
@@ -39,7 +39,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
//[Benchmark(Baseline = true)]
|
||||
public void List_Add_WithCapacity()
|
||||
{
|
||||
var data = TestObjects;
|
||||
@@ -59,7 +59,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
list.AddRange(data);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
[Benchmark(Baseline = true)]
|
||||
public void List_AddRange_WithCapacity()
|
||||
{
|
||||
var data = TestObjects;
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void RecyclableArrayList_Add()
|
||||
{
|
||||
var data = TestObjects;
|
||||
@@ -53,7 +53,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void RecyclableArrayList_Add_WithCapacity()
|
||||
{
|
||||
var data = TestObjects;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
public class RefVsInstanceMemberBenchmarks
|
||||
{
|
||||
private readonly TestCase _testCase = new();
|
||||
private void DoNothing(int count)
|
||||
{
|
||||
_ = count;
|
||||
}
|
||||
|
||||
private class TestCase
|
||||
{
|
||||
private int _count = 123;
|
||||
public int Count
|
||||
{
|
||||
get => _count;
|
||||
set => _count = value;
|
||||
}
|
||||
|
||||
public ref int GetRefCount()
|
||||
{
|
||||
ref int count = ref _count;
|
||||
count = 234;
|
||||
_ = Add(count);
|
||||
return ref count;
|
||||
}
|
||||
|
||||
private int Add(int count)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
_count = 234;
|
||||
_ = Add(_count);
|
||||
return _count;
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Ref()
|
||||
{
|
||||
var count = _testCase.GetRefCount();
|
||||
DoNothing(count);
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void InstanceMember()
|
||||
{
|
||||
var count = _testCase.GetCount();
|
||||
DoNothing(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user