-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructSimpleJob.cs
More file actions
61 lines (56 loc) · 1.94 KB
/
StructSimpleJob.cs
File metadata and controls
61 lines (56 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace Benchmark.Queue
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net70)]
[HideColumns("Error", "StdDev", "Median", "Gen0", "Gen1", "Gen2", "Alloc Ratio", "RatioSD")]
public class StructSimpleJob
{
[Params(100, 1000, 10000, 100000, 250000, 500000, 1000000)]
public int Size;
[Benchmark(Description = $"StackMemoryCollections")]
public void StackMemory()
{
unsafe
{
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobStructHelper.SizeOf * (nuint)Size))
{
var item = new JobStruct(0, 0);
using var queue = new Benchmark.Struct.QueueOfJobStruct((nuint)Size, &memory);
for (int i = 0; i < Size; i++)
{
item.Int32 = i;
item.Int64 = i * 2;
item.JobStruct2.Int32 = 15;
item.JobStruct2.Int64 = 36;
queue.Push(in item);
}
while (queue.TryPop())
{
}
}
}
}
[Benchmark(Baseline = true, Description = "System.Collections.Generic")]
public void SystemCollectionsStack()
{
unsafe
{
var item = new JobStruct(0, 0);
var queue = new System.Collections.Generic.Queue<JobStruct>(Size);
for (int i = 0; i < Size; i++)
{
item.Int32 = i;
item.Int64 = i * 2;
item.JobStruct2.Int32 = 15;
item.JobStruct2.Int64 = 36;
queue.Enqueue(item);
}
while (queue.TryDequeue(out _))
{
}
}
}
}
}