Skip to content

Commit cee51a0

Browse files
committed
Add another benchmark + use explicit pre-alloc'd value types
1 parent b040b8a commit cee51a0

File tree

1 file changed

+31
-16
lines changed
  • src/benchmarks/micro/runtime/System.Reflection

1 file changed

+31
-16
lines changed

src/benchmarks/micro/runtime/System.Reflection/Invoke.cs

+31-16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Invoke
2929
private static MethodInvoker s_method_invoker;
3030
private static MethodInvoker s_method_int_string_struct_class_invoker;
3131
private static MethodInvoker s_method_byref_int_string_struct_class_invoker;
32+
private static MethodInvoker s_method_byref_int_string_struct_class_bool_invoker;
3233
private static ConstructorInvoker s_ctor_int_string_struct_class_invoker;
3334
private static ConstructorInvoker s_ctor_NoParams_invoker;
3435
#endif
@@ -100,6 +101,7 @@ public void Setup()
100101
s_method_invoker = MethodInvoker.Create(s_method);
101102
s_method_int_string_struct_class_invoker = MethodInvoker.Create(s_method_int_string_struct_class);
102103
s_method_byref_int_string_struct_class_invoker = MethodInvoker.Create(s_method_byref_int_string_struct_class);
104+
s_method_byref_int_string_struct_class_bool_invoker = MethodInvoker.Create(s_method_byref_int_string_struct_class_bool);
103105
s_ctor_int_string_struct_class_invoker = ConstructorInvoker.Create(s_ctor_int_string_struct_class);
104106
s_ctor_NoParams_invoker = ConstructorInvoker.Create(typeof(MyClass).GetConstructor(Array.Empty<Type>()));
105107
#endif
@@ -187,23 +189,21 @@ public void StaticMethod4_int_string_struct_class()
187189
[Benchmark(OperationsPerInvoke = Iterations)]
188190
public void StaticMethod4_int_string_struct_class_MethodInvoker()
189191
{
190-
// To make the test more comparable to the MethodBase tests, we need to pre-box the value types.
191-
object boxedInt = 42;
192-
object boxedStruct = default(MyBlittableStruct);
192+
// To make the test more comparable to the MethodBase tests, set up the references and pre-boxed types.
193+
object boxedInt = s_args4[0];
194+
object stringRef = s_args4[1];
195+
object boxedStruct = s_args4[2];
196+
object myClassRef = s_args4[3];
193197

194198
for (int i = 0; i < Iterations; i++)
195199
{
196-
s_method_int_string_struct_class_invoker.Invoke(null, boxedInt, "Hello", boxedStruct, s_MyClass);
200+
s_method_int_string_struct_class_invoker.Invoke(null, boxedInt, stringRef, boxedStruct, myClassRef);
197201
}
198202
}
199203

200204
[Benchmark(OperationsPerInvoke = Iterations)]
201205
public void StaticMethod4_int_string_struct_class_MethodInvokerWithSpan()
202206
{
203-
// To make the test more comparable to the MethodBase tests, we need to pre-box the value types.
204-
object boxedInt = 42;
205-
object boxedStruct = default(MyBlittableStruct);
206-
207207
for (int i = 0; i < Iterations; i++)
208208
{
209209
s_method_int_string_struct_class_invoker.Invoke(null, new Span<object>(s_args4));
@@ -224,13 +224,15 @@ public void StaticMethod4_ByRefParams_int_string_struct_class()
224224
[Benchmark(OperationsPerInvoke = Iterations)]
225225
public void StaticMethod4_ByRefParams_int_string_struct_class_MethodInvoker()
226226
{
227-
// To make the test more comparable to the MethodBase tests, we need to pre-box the value types.
228-
object boxedInt = 42;
229-
object boxedStruct = default(MyBlittableStruct);
227+
// To make the test more comparable to the MethodBase tests, set up the references and pre-boxed types.
228+
object boxedInt = s_args4[0];
229+
object stringRef = s_args4[1];
230+
object boxedStruct = s_args4[2];
231+
object myClassRef = s_args4[3];
230232

231233
for (int i = 0; i < Iterations; i++)
232234
{
233-
s_method_byref_int_string_struct_class_invoker.Invoke(null, boxedInt, "Hello", boxedStruct, s_MyClass);
235+
s_method_byref_int_string_struct_class_invoker.Invoke(null, boxedInt, stringRef, boxedStruct, myClassRef);
234236
}
235237
}
236238
#endif
@@ -245,6 +247,17 @@ public void StaticMethod5_ByRefParams_int_string_struct_class_bool()
245247
}
246248
}
247249

250+
#if NET8_0_OR_GREATER
251+
[Benchmark(OperationsPerInvoke = Iterations)]
252+
public void StaticMethod5_ByRefParams_int_string_struct_class_bool_MethodInvoker()
253+
{
254+
for (int i = 0; i < Iterations; i++)
255+
{
256+
s_method_byref_int_string_struct_class_bool_invoker.Invoke(null, new Span<object>(s_args5));
257+
}
258+
}
259+
#endif
260+
248261
[Benchmark(OperationsPerInvoke = Iterations)]
249262
public void Ctor0_NoParams()
250263
{
@@ -301,13 +314,15 @@ public void Ctor4_int_string_struct_class()
301314
[Benchmark(OperationsPerInvoke = Iterations)]
302315
public void Ctor4_int_string_struct_class_ConstructorInvoker()
303316
{
304-
// To make the test more comparable to the MethodBase tests, we need to pre-box the value types.
305-
object boxedInt = 42;
306-
object boxedStruct = default(MyBlittableStruct);
317+
// To make the test more comparable to the MethodBase tests, set up the references and pre-boxed types.
318+
object boxedInt = s_args4[0];
319+
object stringRef = s_args4[1];
320+
object boxedStruct = s_args4[2];
321+
object myClassRef = s_args4[3];
307322

308323
for (int i = 0; i < Iterations; i++)
309324
{
310-
s_ctor_int_string_struct_class_invoker.Invoke(boxedInt, "Hello", boxedStruct, s_MyClass);
325+
s_ctor_int_string_struct_class_invoker.Invoke(boxedInt, stringRef, boxedStruct, myClassRef);
311326
}
312327
}
313328
#endif

0 commit comments

Comments
 (0)