File tree 1 file changed +65
-0
lines changed
1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -195,3 +195,68 @@ mod tests {
195
195
unsafe { assert_eq ! ( did_run, true ) ; }
196
196
}
197
197
}
198
+
199
+ /// Completely miscellaneous language-construct benchmarks.
200
+ #[ cfg( test) ]
201
+ mod bench {
202
+
203
+ use extra:: test:: BenchHarness ;
204
+ use option:: { Some , None } ;
205
+
206
+ // Static/dynamic method dispatch
207
+
208
+ struct Struct {
209
+ field : int
210
+ }
211
+
212
+ trait Trait {
213
+ fn method ( & self ) -> int ;
214
+ }
215
+
216
+ impl Trait for Struct {
217
+ fn method ( & self ) -> int {
218
+ self . field
219
+ }
220
+ }
221
+
222
+ #[ bench]
223
+ fn trait_vtable_method_call ( bh : & mut BenchHarness ) {
224
+ let s = Struct { field : 10 } ;
225
+ let t = & s as & Trait ;
226
+ do bh. iter {
227
+ t. method ( ) ;
228
+ }
229
+ }
230
+
231
+ #[ bench]
232
+ fn trait_static_method_call ( bh : & mut BenchHarness ) {
233
+ let s = Struct { field : 10 } ;
234
+ do bh. iter {
235
+ s. method ( ) ;
236
+ }
237
+ }
238
+
239
+ // Overhead of various match forms
240
+
241
+ #[ bench]
242
+ fn match_option_some ( bh : & mut BenchHarness ) {
243
+ let x = Some ( 10 ) ;
244
+ do bh. iter {
245
+ let _q = match x {
246
+ Some ( y) => y,
247
+ None => 11
248
+ } ;
249
+ }
250
+ }
251
+
252
+ #[ bench]
253
+ fn match_vec_pattern ( bh : & mut BenchHarness ) {
254
+ let x = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
255
+ do bh. iter {
256
+ let _q = match x {
257
+ [ 1 , 2 , 3 , .._] => 10 ,
258
+ _ => 11
259
+ } ;
260
+ }
261
+ }
262
+ }
You can’t perform that action at this time.
0 commit comments