Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dd0f452

Browse files
committed
Update performance tests
Add inner iterations to all performance tests in the perflab directory. This is because we were measuring a time that was to small, and the results were not useful. This should also reduce the number of high level iterations we run as well.
1 parent 6340f35 commit dd0f452

File tree

9 files changed

+571
-449
lines changed

9 files changed

+571
-449
lines changed

tests/src/performance/perflab/BlockCopyPerf.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class BlockCopyPerf
99
{
10-
[Benchmark]
10+
[Benchmark(InnerIterationCount=1000000)]
1111
[InlineData(0)]
1212
[InlineData(10)]
1313
[InlineData(100)]
@@ -19,6 +19,7 @@ public static void CallBlockCopy(int numElements)
1919

2020
foreach (var iteration in Benchmark.Iterations)
2121
using (iteration.StartMeasurement())
22-
Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements);
22+
for(int i=0; i<Benchmark.InnerIterationCount; i++)
23+
Buffer.BlockCopy(bytes, 0, bytes, numElements, numElements);
2324
}
2425
}

tests/src/performance/perflab/CastingPerf.cs

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -130,236 +130,260 @@ static CastingPerf()
130130
orvt = new FooORVT[NUM_ARRAY_ELEMENTS];
131131
}
132132

133-
[Benchmark]
133+
[Benchmark(InnerIterationCount=100000)]
134134
public static void ObjFooIsObj()
135135
{
136136
foreach (var iteration in Benchmark.Iterations)
137137
using (iteration.StartMeasurement())
138-
o = foo;
138+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
139+
o = foo;
139140
}
140141

141-
[Benchmark]
142+
[Benchmark(InnerIterationCount=100000)]
142143
public static void ObjFooIsObj2()
143144
{
144145
foreach (var iteration in Benchmark.Iterations)
145146
using (iteration.StartMeasurement())
146-
o_ar = foo;
147+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
148+
o_ar = foo;
147149
}
148150

149-
[Benchmark]
151+
[Benchmark(InnerIterationCount=100000)]
150152
public static void ObjObjIsFoo()
151153
{
152154
o = foo;
153155

154156
foreach (var iteration in Benchmark.Iterations)
155157
using (iteration.StartMeasurement())
156-
o_ar = (Object[])o;
158+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
159+
o_ar = (Object[])o;
157160
}
158161

159-
[Benchmark]
162+
[Benchmark(InnerIterationCount=100000)]
160163
public static void FooObjIsFoo()
161164
{
162165
o = foo;
163166

164167
foreach (var iteration in Benchmark.Iterations)
165168
using (iteration.StartMeasurement())
166-
f = (Foo[])o;
169+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
170+
f = (Foo[])o;
167171
}
168172

169-
[Benchmark]
173+
[Benchmark(InnerIterationCount=100000)]
170174
public static void FooObjIsFoo2()
171175
{
172176
o_ar = foo;
173177

174178
foreach (var iteration in Benchmark.Iterations)
175179
using (iteration.StartMeasurement())
176-
f = (Foo[])o_ar;
180+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
181+
f = (Foo[])o_ar;
177182
}
178183

179-
[Benchmark]
184+
[Benchmark(InnerIterationCount=100000)]
180185
public static void FooObjIsNull()
181186
{
182187
foreach (var iteration in Benchmark.Iterations)
183188
using (iteration.StartMeasurement())
184-
o = (Foo[])n;
189+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
190+
o = (Foo[])n;
185191
}
186192

187-
[Benchmark]
193+
[Benchmark(InnerIterationCount=100000)]
188194
public static void FooObjIsDescendant()
189195
{
190196
o = foo_5;
191197

192198
foreach (var iteration in Benchmark.Iterations)
193199
using (iteration.StartMeasurement())
194-
f = (Foo[])o;
200+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
201+
f = (Foo[])o;
195202
}
196203

197-
[Benchmark]
204+
[Benchmark(InnerIterationCount=100000)]
198205
public static void IFooFooIsIFoo()
199206
{
200207
foreach (var iteration in Benchmark.Iterations)
201208
using (iteration.StartMeasurement())
202-
ifo = foo;
209+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
210+
ifo = foo;
203211
}
204212

205-
[Benchmark]
213+
[Benchmark(InnerIterationCount=100000)]
206214
public static void IFooObjIsIFoo()
207215
{
208216
o = foo;
209217

210218
foreach (var iteration in Benchmark.Iterations)
211219
using (iteration.StartMeasurement())
212-
ifo = (IFoo[])o;
220+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
221+
ifo = (IFoo[])o;
213222
}
214223

215-
[Benchmark]
224+
[Benchmark(InnerIterationCount=100000)]
216225
public static void IFooObjIsIFooInterAlia()
217226
{
218227
o = foo2;
219228

220229
foreach (var iteration in Benchmark.Iterations)
221230
using (iteration.StartMeasurement())
222-
if_5 = (IFoo_5[])o;
231+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
232+
if_5 = (IFoo_5[])o;
223233
}
224234

225-
[Benchmark]
235+
[Benchmark(InnerIterationCount=100000)]
226236
public static void IFooObjIsDescendantOfIFoo()
227237
{
228238
o = foo_5;
229239

230240
foreach (var iteration in Benchmark.Iterations)
231241
using (iteration.StartMeasurement())
232-
ifo = (IFoo[])o;
242+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
243+
ifo = (IFoo[])o;
233244
}
234245

235-
[Benchmark]
246+
[Benchmark(InnerIterationCount=100000)]
236247
public static void ObjInt()
237248
{
238249
foreach (var iteration in Benchmark.Iterations)
239250
using (iteration.StartMeasurement())
240-
o = (Object)j;
251+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
252+
o = (Object)j;
241253
}
242254

243-
[Benchmark]
255+
[Benchmark(InnerIterationCount=100000)]
244256
public static void IntObj()
245257
{
246258
o = (Object)j;
247259

248260
foreach (var iteration in Benchmark.Iterations)
249261
using (iteration.StartMeasurement())
250-
k = (int[])o;
262+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
263+
k = (int[])o;
251264
}
252265

253-
[Benchmark]
266+
[Benchmark(InnerIterationCount=100000)]
254267
public static void ObjScalarValueType()
255268
{
256269
foreach (var iteration in Benchmark.Iterations)
257270
using (iteration.StartMeasurement())
258-
o = svt;
271+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
272+
o = svt;
259273
}
260274

261-
[Benchmark]
275+
[Benchmark(InnerIterationCount=100000)]
262276
public static void ScalarValueTypeObj()
263277
{
264278
o = svt;
265279

266280
foreach (var iteration in Benchmark.Iterations)
267281
using (iteration.StartMeasurement())
268-
svt = (FooSVT[])o;
282+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
283+
svt = (FooSVT[])o;
269284
}
270285

271-
[Benchmark]
286+
[Benchmark(InnerIterationCount=100000)]
272287
public static void ObjObjrefValueType()
273288
{
274289
foreach (var iteration in Benchmark.Iterations)
275290
using (iteration.StartMeasurement())
276-
o = (Object)orvt;
291+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
292+
o = (Object)orvt;
277293
}
278294

279-
[Benchmark]
295+
[Benchmark(InnerIterationCount=100000)]
280296
public static void ObjrefValueTypeObj()
281297
{
282298
o = (Object)orvt;
283299

284300
foreach (var iteration in Benchmark.Iterations)
285301
using (iteration.StartMeasurement())
286-
orvt = (FooORVT[])o;
302+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
303+
orvt = (FooORVT[])o;
287304
}
288305

289-
[Benchmark]
306+
[Benchmark(InnerIterationCount=100000)]
290307
public static void FooObjCastIfIsa()
291308
{
292309
o = foo;
293310

294311
foreach (var iteration in Benchmark.Iterations)
295312
using (iteration.StartMeasurement())
296-
if (o is Foo[])
297-
f = (Foo[])o;
313+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
314+
if (o is Foo[])
315+
f = (Foo[])o;
298316
}
299317

300-
[Benchmark]
318+
[Benchmark(InnerIterationCount=100000)]
301319
public static bool CheckObjIsInterfaceYes()
302320
{
303321
bool res = false;
304322
Object obj = new MyClass1();
305323
foreach (var iteration in Benchmark.Iterations)
306324
using (iteration.StartMeasurement())
307-
res = obj is IMyInterface1;
325+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
326+
res = obj is IMyInterface1;
308327
return res;
309328
}
310329

311-
[Benchmark]
330+
[Benchmark(InnerIterationCount=100000)]
312331
public static bool CheckObjIsInterfaceNo()
313332
{
314333
bool res = false;
315334
Object obj = new MyClass2();
316335
foreach (var iteration in Benchmark.Iterations)
317336
using (iteration.StartMeasurement())
318-
res = obj is IMyInterface1;
337+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
338+
res = obj is IMyInterface1;
319339
return res;
320340
}
321341

322-
[Benchmark]
342+
[Benchmark(InnerIterationCount=100000)]
323343
public static bool CheckIsInstAnyIsInterfaceYes()
324344
{
325345
bool res = false;
326346
Object obj = new MyClass4<List<string>>();
327347
foreach (var iteration in Benchmark.Iterations)
328348
using (iteration.StartMeasurement())
329-
res = obj is IMyInterface1;
349+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
350+
res = obj is IMyInterface1;
330351
return res;
331352
}
332353

333-
[Benchmark]
354+
[Benchmark(InnerIterationCount=100000)]
334355
public static bool CheckIsInstAnyIsInterfaceNo()
335356
{
336357
bool res = false;
337358
Object obj = new MyClass4<List<string>>();
338359
foreach (var iteration in Benchmark.Iterations)
339360
using (iteration.StartMeasurement())
340-
res = obj is IMyInterface2;
361+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
362+
res = obj is IMyInterface2;
341363
return res;
342364
}
343365

344-
[Benchmark]
366+
[Benchmark(InnerIterationCount=100000)]
345367
public static bool CheckArrayIsInterfaceYes()
346368
{
347369
bool res = false;
348370
Object[] arr = new MyClass1[5];
349371
foreach (var iteration in Benchmark.Iterations)
350372
using (iteration.StartMeasurement())
351-
res = arr is IMyInterface1[];
373+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
374+
res = arr is IMyInterface1[];
352375
return res;
353376
}
354377

355-
[Benchmark]
378+
[Benchmark(InnerIterationCount=100000)]
356379
public static bool CheckArrayIsInterfaceNo()
357380
{
358381
bool res = false;
359382
Object[] arr = new MyClass2[5];
360383
foreach (var iteration in Benchmark.Iterations)
361384
using (iteration.StartMeasurement())
362-
res = arr is IMyInterface1[];
385+
for (int i = 0; i < Benchmark.InnerIterationCount; i++)
386+
res = arr is IMyInterface1[];
363387
return res;
364388
}
365389
}

0 commit comments

Comments
 (0)