-
Notifications
You must be signed in to change notification settings - Fork 272
/
Activator.cs
32 lines (26 loc) · 1.13 KB
/
Activator.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Filters;
using MicroBenchmarks;
namespace System.Reflection
{
[BenchmarkCategory(Categories.Runtime, Categories.Reflection)]
[GenericTypeArguments(typeof(EmptyStruct))] // value type
[GenericTypeArguments(typeof(EmptyClass))] // reference type
public class Activator<T>
{
private readonly string _assemblyName = typeof(T).Assembly.FullName;
private readonly string _typeName = typeof(T).FullName;
[Benchmark]
public T CreateInstanceGeneric() => System.Activator.CreateInstance<T>();
[Benchmark]
public object CreateInstanceType() => System.Activator.CreateInstance(typeof(T));
[Benchmark]
[AotFilter("Not supported.")]
public object CreateInstanceNames() => System.Activator.CreateInstance(_assemblyName, _typeName);
}
public class EmptyClass { }
public struct EmptyStruct { }
}