forked from microsoft/CsWinRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryInterface.cs
219 lines (186 loc) · 6.37 KB
/
QueryInterface.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using BenchmarkComponent;
using BenchmarkDotNet.Attributes;
using Windows.ApplicationModel.Chat;
namespace Benchmarks
{
class ManagedObjectWithInterfaces : IIntProperties, IBoolProperties
{
private int intProperty;
private bool boolProperty;
public int IntProperty { get => intProperty; set => intProperty = value; }
public bool BoolProperty { get => boolProperty; set => boolProperty = value; }
}
class ManagedComposableObjectWithInterfaces : Composable, IIntProperties
{
private int intProperty;
public int IntProperty { get => intProperty; set => intProperty = value; }
}
[MemoryDiagnoser]
public class QueryInterfacePerf
{
ClassWithMultipleInterfaces instance;
ChatMessage message;
ManagedObjectWithInterfaces managedObject;
ManagedComposableObjectWithInterfaces composableObject;
ClassWithFastAbi fastAbiInstance;
ClassWithFastAbiDerived fastAbiDerivedInstance;
[GlobalSetup]
public void Setup()
{
instance = new ClassWithMultipleInterfaces();
message = new ChatMessage();
managedObject = new ManagedObjectWithInterfaces();
composableObject = new ManagedComposableObjectWithInterfaces();
fastAbiInstance = new ClassWithFastAbi();
fastAbiDerivedInstance = new ClassWithFastAbiDerived();
}
[Benchmark]
public int QueryDefaultInterface()
{
return instance.DefaultIntProperty;
}
[Benchmark]
public int QueryNonDefaultInterface()
{
return instance.IntProperty;
}
[Benchmark]
public int QueryFastAbiDefaultInterface()
{
return fastAbiInstance.DefaultIntProperty;
}
[Benchmark]
public int QueryFastAbiNonDefaultInterface()
{
return fastAbiInstance.NonDefaultIntProperty;
}
[Benchmark]
public int QueryFastAbiDerivedDefaultInterface()
{
return fastAbiDerivedInstance.DerivedDefaultIntProperty;
}
[Benchmark]
public int QueryFastAbiComposedNonDefaultInterface()
{
return fastAbiDerivedInstance.DerivedNonDefaultIntProperty;
}
[Benchmark]
public int QueryFastAbiComposedBaseDefaultInterface()
{
return fastAbiDerivedInstance.DefaultIntProperty;
}
[Benchmark]
public int QueryFastAbiComposedBaseNonDefaultInterface()
{
return fastAbiDerivedInstance.NonDefaultIntProperty;
}
[Benchmark]
public bool QueryNonDefaultInterface2()
{
return instance.BoolProperty;
}
[Benchmark]
public void QueryDefaultInterfaceSetProperty()
{
instance.DefaultIntProperty = 4;
}
[Benchmark]
public void QueryNonDefaultInterfaceSetProperty()
{
instance.IntProperty = 4;
}
[Benchmark]
public bool QuerySDKDefaultInterface()
{
return message.IsForwardingDisabled;
}
[Benchmark]
public bool QuerySDKNonDefaultInterface()
{
return message.IsSeen;
}
[Benchmark]
public object DefaultObjectParameters()
{
instance.DefaultObjectProperty = new ClassWithMultipleInterfaces();
return instance.DefaultObjectProperty;
}
[Benchmark]
public object DefaultStringParameters()
{
instance.DefaultStringProperty = "Hello";
return instance.DefaultStringProperty;
}
[Benchmark]
public object DynamicCast()
{
return (ClassWithMarshalingRoutines)instance.NewObject();
}
// The following 4 benchmarks try to benchmark the time taken for the first call
// rather than the mean time over several calls. It has the overhead of the object
// construction, but it can be used to track regressions to performance.
[Benchmark]
public int ConstructAndQueryDefaultInterfaceFirstCall()
{
ClassWithMultipleInterfaces instance2 = new ClassWithMultipleInterfaces();
return instance2.DefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryNonDefaultInterfaceFirstCall()
{
ClassWithMultipleInterfaces instance2 = new ClassWithMultipleInterfaces();
return instance2.IntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbi();
return instance2.DefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiNonDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbi();
return instance2.NonDefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiDerivedDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbiDerived();
return instance2.DerivedDefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiDerivedNonDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbiDerived();
return instance2.DerivedNonDefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiDerivedBaseDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbiDerived();
return instance2.DefaultIntProperty;
}
[Benchmark]
public int ConstructAndQueryFastAbiDerivedBaseNonDefaultInterfaceFirstCall()
{
var instance2 = new ClassWithFastAbiDerived();
return instance2.NonDefaultIntProperty;
}
[Benchmark]
public int StaticPropertyCall()
{
return Windows.System.Power.PowerManager.RemainingChargePercent;
}
[Benchmark]
public void QueryInterfaceOnManagedObject()
{
instance.QueryBoolInterface(managedObject);
}
[Benchmark]
public void QueryNativeInterfaceOnComposedObject()
{
instance.QueryBoolInterface(composableObject);
}
}
}