Skip to content

Commit

Permalink
Add object benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cricle committed May 30, 2023
1 parent cd01a35 commit 97e200c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/UnionType.Benchmarks/Runs/StoreObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BenchmarkDotNet.Attributes;

namespace UnionType.Benchmarks.Runs
{
[MemoryDiagnoser]
public class StoreObject
{
[Params(500, 1_000_000)]
public int Count { get; set; }

[Benchmark(Baseline = true)]
public void Normal()
{
var obj = new object[Count];
for (int i = 0; i < Count; i++)
{
obj[i] = new object();
}
}
[Benchmark]
public void UnionObject()
{
var obj = new UnionValue[Count];
for (int i = 0; i < Count; i++)
{
obj[i] = new UnionValue { Object = new object() };
}
for (int i = 0; i < obj.Length; i++)
{
obj[i].Dispose();
}
}
}

}

0 comments on commit 97e200c

Please sign in to comment.