Skip to content

Commit

Permalink
Merge pull request #48 from faustodavid/RedesignBenchmarks
Browse files Browse the repository at this point in the history
Redesign benchmarks
  • Loading branch information
faustodavid authored Feb 4, 2020
2 parents 7c775cc + cd38bee commit a803e89
Show file tree
Hide file tree
Showing 16 changed files with 799 additions and 376 deletions.
1 change: 1 addition & 0 deletions perf/ListPool.Benchmarks/ListPool.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="Spreads.Core" Version="2020.0.114" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>

Expand Down
48 changes: 19 additions & 29 deletions perf/ListPool.Benchmarks/ListPoolAddBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,43 @@ namespace ListPool.Benchmarks
[GcConcurrent]
public class ListPoolAddBenchmarks
{
private List<int> _list;
private ListPool<int> _listPool;
private ValueListPool<int> _valueListPool;

[Params(1000)]
[Params(100, 1000, 10000)]
public int N { get; set; }

[IterationSetup]
public void IterationSetup()
{
_list = new List<int>(N);
_listPool = new ListPool<int>(N);
_valueListPool = new ValueListPool<int>(N);
}

[IterationCleanup]
public void IterationCleanup()
{
_listPool.Dispose();
_valueListPool.Dispose();
}

[Benchmark(Baseline = true)]
public void List()
public int List()
{
for (int i = 0; i < N - 1; i++)
List<int> list = new List<int>(N);
for (int i = 0; i < N; i++)
{
_list.Add(i);
list.Add(i);
}

return list.Count;
}

[Benchmark]
public void ListPool()
public int ListPool()
{
for (int i = 0; i < N - 1; i++)
using ListPool<int> list = new ListPool<int>(N);
for (int i = 0; i < N; i++)
{
_listPool.Add(i);
list.Add(i);
}

return list.Count;
}

[Benchmark]
public void ValueListPool()
public int ValueListPool()
{
for (int i = 0; i < N - 1; i++)
using ValueListPool<int> list = new ValueListPool<int>(N);
for (int i = 0; i < N; i++)
{
_valueListPool.Add(i);
list.Add(i);
}

return list.Count;
}
}
}
9 changes: 5 additions & 4 deletions perf/ListPool.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Running;

namespace ListPool.Benchmarks
{
internal class Program
{
private static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
Console.ReadLine();
while (true)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Utf8JsonDeserializeListOfIntBenchmarks
{
private byte[] _serializedList;

[Params(100, 1000, 1000)]
[Params(100, 1_000, 10_000)]
public int N { get; set; }

[GlobalSetup]
Expand All @@ -36,5 +36,18 @@ public int ListPool()
using ListPool<int> list = Utf8Json.JsonSerializer.Deserialize<ListPool<int>>(_serializedList);
return list.Count;
}
[Benchmark]
public int ListPool_Spreads()
{
using ListPool<int> list = Spreads.Serialization.Utf8Json.JsonSerializer.Deserialize<ListPool<int>>(_serializedList);
return list.Count;
}

[Benchmark]
public int List_Spreads()
{
List<int> list = Spreads.Serialization.Utf8Json.JsonSerializer.Deserialize<List<int>>(_serializedList);
return list.Count;
}
}
}
59 changes: 59 additions & 0 deletions perf/ListPool.Benchmarks/Utf8JsonSerializeListOfIntBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using Utf8Json;

namespace ListPool.Benchmarks
{
[RPlotExporter]
[RankColumn]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[MemoryDiagnoser]
[GcServer(true)]
[GcConcurrent]
public class Utf8JsonSerializeListOfIntBenchmarks
{
private List<int> _list;
private ListPool<int> _listPool;

[Params(100, 1_000, 10_000)]
public int N { get; set; }

[GlobalSetup]
public void GlobalSetup()
{
var items = Enumerable.Range(0, N).ToArray();
_listPool = items.ToListPool();
_list = items.ToList();
}

[GlobalCleanup]
public void GlobalCleanup()
{
_listPool.Dispose();
}

[Benchmark(Baseline = true)]
public int List()
{
byte[] serializedItems = JsonSerializer.Serialize(_list);
return serializedItems.Length;
}

[Benchmark]
public int ListPool()
{
byte[] serializedItems = JsonSerializer.Serialize(_listPool);
return serializedItems.Length;
}


[Benchmark]
public int ListPool_Spreads()
{
byte[] serializedItems = Spreads.Serialization.Utf8Json.JsonSerializer.Serialize(_listPool);
return serializedItems.Length;
}
}
}
9 changes: 0 additions & 9 deletions src/ListPool/IValueEnumerable.cs

This file was deleted.

Loading

0 comments on commit a803e89

Please sign in to comment.