-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIEnumerableParameter.cs
137 lines (113 loc) · 3.13 KB
/
IEnumerableParameter.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine.Profiling;
using UnityEngine.TestTools.Constraints;
using Is = UnityEngine.TestTools.Constraints.Is;
namespace MH.GCTests
{
public class IEnumerableParameter
{
const int ELEM_COUNT = 10;
const int LOOP_COUNT = 100000;
List<DummyObjA> _cache = new List<DummyObjA>();
[OneTimeSetUp]
public void Init()
{
GC.Collect();
Profiler.enabled = true;
for(int i=0; i<ELEM_COUNT; ++i)
_cache.Add(new DummyObjA(i));
}
[OneTimeTearDown]
public void Fini()
{
Profiler.enabled = false;
_cache.Clear();
}
[Test]
public void OK_List_AddRange()
{
var cont = new List<DummyObjA>();
cont.AddRange(_cache);
cont.Clear();
Assert.That(
() =>
{
cont.Clear();
cont.AddRange(_cache);
},
Is.Not.AllocatingGCMemory()
);
GC.Collect();
long startMem = Profiler.GetMonoUsedSizeLong();
}
[Test]
public void OK_List_InsertRange()
{
var cont = new List<DummyObjA>();
cont.AddRange(_cache);
cont.Clear();
Assert.That(
() =>
{
cont.Clear();
cont.InsertRange(0, _cache);
},
Is.Not.AllocatingGCMemory()
);
}
[Test]
public void BAD_HashSet_UnionWith()
{
var cont = new HashSet<DummyObjA>();
cont.UnionWith(_cache);
cont.Clear();
GC.Collect();
Assert.That(
() => {
cont.UnionWith(_cache);
}, Is.AllocatingGCMemory()
);
}
[Test]
public void OK_HashSet_IntersectWith()
{
var cont = new HashSet<DummyObjA>();
cont.UnionWith(_cache);
cont.Clear();
GC.Collect();
//------------------//
Assert.That(
() => cont.IntersectWith(_cache) ,
Is.Not.AllocatingGCMemory()
);
}
[Test]
public void OK_HashSet_ExceptWith()
{
var cont = new HashSet<DummyObjA>();
cont.UnionWith(_cache);
cont.Clear();
GC.Collect();
//------------------//
Assert.That(
() => cont.ExceptWith(_cache),
Is.Not.AllocatingGCMemory()
);
}
[Test]
public void BAD_HashSet_SymExcept()
{
var cont = new HashSet<DummyObjA>();
cont.UnionWith(_cache);
cont.Clear();
Assert.That(
() =>cont.SymmetricExceptWith(_cache),
Is.AllocatingGCMemory()
);
}
}
}