Skip to content

Commit 6179d98

Browse files
author
Vyacheslav
committed
update benchmark
1 parent 3aef8a0 commit 6179d98

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

Src/Benchmarks/Model/JobClass.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,30 @@ long int64
2323

2424
public long Int64;
2525
public int Int32;
26+
27+
public JobClass2 JobClass2;
28+
}
29+
30+
[GenerateHelper]
31+
[GenerateStack]
32+
[GenerateWrapper]
33+
public class JobClass2
34+
{
35+
public JobClass2()
36+
{
37+
38+
}
39+
40+
public JobClass2(
41+
int int32,
42+
long int64
43+
)
44+
{
45+
Int32 = int32;
46+
Int64 = int64;
47+
}
48+
49+
public long Int64;
50+
public int Int32;
2651
}
2752
}

Src/Benchmarks/Stack/Optimal/ClassOptimalJob.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public void StackMemory()
1616
{
1717
unsafe
1818
{
19-
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobClassHelper.GetSize() * (nuint)Size))
19+
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobClassHelper.GetSize() + (JobClassHelper.GetSize() * (nuint)Size)))
2020
{
21-
var item = new JobClass(0, 0);
21+
var item = new Benchmark.Struct.JobClassWrapper(&memory);
2222
for (int j = 0; j < 100; j++)
2323
{
2424
{
@@ -27,7 +27,10 @@ public void StackMemory()
2727
{
2828
item.Int32 = i;
2929
item.Int64 = i * 2;
30-
stack.Push(in item);
30+
var jc2 = Benchmark.JobClassHelper.GetJobClass2Ptr(item.Ptr);
31+
Benchmark.JobClass2Helper.SetInt32Value(in jc2, i + 3);
32+
Benchmark.JobClass2Helper.SetInt64Value(in jc2, i * 3);
33+
stack.Push(item.Ptr);
3134
}
3235

3336
if(j > 50)
@@ -47,7 +50,10 @@ public void StackMemory()
4750
{
4851
item.Int32 = i;
4952
item.Int64 = i * 2;
50-
stack2.Push(in item);
53+
var jc2 = Benchmark.JobClassHelper.GetJobClass2Ptr(item.Ptr);
54+
Benchmark.JobClass2Helper.SetInt32Value(in jc2, i + 3);
55+
Benchmark.JobClass2Helper.SetInt64Value(in jc2, i * 3);
56+
stack2.Push(item.Ptr);
5157
}
5258

5359
if (j > 50)
@@ -76,7 +82,12 @@ public void SystemCollectionsStack()
7682
var stack = new System.Collections.Generic.Stack<JobClass>(Size);
7783
for (int i = 0; i < Size; i++)
7884
{
79-
stack.Push(new JobClass(i, i * 2));
85+
stack.Push(
86+
new JobClass(i, i * 2)
87+
{
88+
JobClass2 = new JobClass2(i + 3, i * 3)
89+
}
90+
);
8091
}
8192

8293
if (j > 50)
@@ -94,7 +105,12 @@ public void SystemCollectionsStack()
94105
var stack2 = new System.Collections.Generic.Stack<JobClass>(Size);
95106
for (int i = 0; i < Size; i++)
96107
{
97-
stack2.Push(new JobClass(i, i * 2));
108+
stack2.Push(
109+
new JobClass(i, i * 2)
110+
{
111+
JobClass2 = new JobClass2(i + 3, i * 3)
112+
}
113+
);
98114
}
99115

100116
if (j > 50)

Src/Benchmarks/Stack/Simple/ClassSimpleJob.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ public void StackMemory()
1616
{
1717
unsafe
1818
{
19-
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobClassHelper.GetSize() * (nuint)Size))
19+
using (var memory = new StackMemoryCollections.Struct.StackMemory(JobClassHelper.GetSize() + (JobClassHelper.GetSize() * (nuint)Size)))
2020
{
21-
var item = new JobClass(0, 0);
21+
var item = new Benchmark.Struct.JobClassWrapper(&memory);
2222
using var stack = new Benchmark.Struct.StackOfJobClass((nuint)Size, &memory);
2323
for (int i = 0; i < Size; i++)
2424
{
2525
item.Int32 = i;
2626
item.Int64 = i * 2;
27-
stack.Push(in item);
27+
var jc2 = Benchmark.JobClassHelper.GetJobClass2Ptr(item.Ptr);
28+
Benchmark.JobClass2Helper.SetInt32Value(in jc2, i + 3);
29+
Benchmark.JobClass2Helper.SetInt64Value(in jc2, i * 3);
30+
stack.Push(item.Ptr);
2831
}
2932

3033
while (stack.TryPop())
@@ -42,7 +45,12 @@ public void SystemCollectionsStack()
4245
var stack = new System.Collections.Generic.Stack<JobClass>(Size);
4346
for (int i = 0; i < Size; i++)
4447
{
45-
stack.Push(new JobClass(i, i * 2));
48+
stack.Push(
49+
new JobClass(i, i * 2)
50+
{
51+
JobClass2 = new JobClass2(i + 3, i * 3)
52+
}
53+
);
4654
}
4755

4856
while (stack.TryPop(out _))

0 commit comments

Comments
 (0)