File tree 9 files changed +238
-2
lines changed
9 files changed +238
-2
lines changed Original file line number Diff line number Diff line change @@ -703,3 +703,27 @@ mod test {
703
703
assert_eq ! ( n, None ) ;
704
704
}
705
705
}
706
+
707
+ #[ cfg( test) ]
708
+ mod bench {
709
+ use extra:: test:: BenchHarness ;
710
+ use rand:: { XorShiftRng , RngUtil } ;
711
+ use uint;
712
+ use float;
713
+
714
+ #[ bench]
715
+ fn uint_to_str_rand ( bh : & mut BenchHarness ) {
716
+ let mut rng = XorShiftRng :: new ( ) ;
717
+ do bh. iter {
718
+ uint:: to_str ( rng. gen ( ) ) ;
719
+ }
720
+ }
721
+
722
+ #[ bench]
723
+ fn float_to_str_rand ( bh : & mut BenchHarness ) {
724
+ let mut rng = XorShiftRng :: new ( ) ;
725
+ do bh. iter {
726
+ float:: to_str ( rng. gen ( ) ) ;
727
+ }
728
+ }
729
+ }
Original file line number Diff line number Diff line change @@ -81,3 +81,28 @@ pub trait Shr<RHS,Result> {
81
81
pub trait Index < Index , Result > {
82
82
fn index ( & self , index : & Index ) -> Result ;
83
83
}
84
+
85
+ #[ cfg( test) ]
86
+ mod bench {
87
+
88
+ use extra:: test:: BenchHarness ;
89
+ use ops:: Drop ;
90
+
91
+ // Overhead of dtors
92
+
93
+ struct HasDtor {
94
+ x : int
95
+ }
96
+
97
+ impl Drop for HasDtor {
98
+ fn drop ( & self ) {
99
+ }
100
+ }
101
+
102
+ #[ bench]
103
+ fn alloc_obj_with_dtor ( bh : & mut BenchHarness ) {
104
+ do bh. iter {
105
+ HasDtor { x : 10 } ;
106
+ }
107
+ }
108
+ }
Original file line number Diff line number Diff line change @@ -890,7 +890,7 @@ pub fn random<T: Rand>() -> T {
890
890
}
891
891
892
892
#[ cfg( test) ]
893
- mod tests {
893
+ mod test {
894
894
use option:: { Option , Some } ;
895
895
use super :: * ;
896
896
@@ -1109,3 +1109,37 @@ mod tests {
1109
1109
}
1110
1110
}
1111
1111
}
1112
+
1113
+ #[ cfg( test) ]
1114
+ mod bench {
1115
+ use extra:: test:: BenchHarness ;
1116
+ use rand:: * ;
1117
+ use sys:: size_of;
1118
+
1119
+ #[ bench]
1120
+ fn rand_xorshift( bh: & mut BenchHarness ) {
1121
+ let mut rng = XorShiftRng :: new ( ) ;
1122
+ do bh. iter {
1123
+ rng. gen :: <uint> ( ) ;
1124
+ }
1125
+ bh. bytes = size_of:: <uint >( ) as u64 ;
1126
+ }
1127
+
1128
+ #[ bench]
1129
+ fn rand_isaac( bh: & mut BenchHarness ) {
1130
+ let mut rng = IsaacRng : : new( ) ;
1131
+ do bh. iter {
1132
+ rng. gen :: <uint >( ) ;
1133
+ }
1134
+ bh. bytes = size_of:: <uint>( ) as u64 ;
1135
+ }
1136
+
1137
+ #[ bench]
1138
+ fn rand_shuffle_100( bh: & mut BenchHarness ) {
1139
+ let mut rng = XorShiftRng :: new( ) ;
1140
+ let x : & mut [ uint] = [ 1 , ..100 ] ;
1141
+ do bh. iter {
1142
+ rng. shuffle_mut( x) ;
1143
+ }
1144
+ }
1145
+ }
Original file line number Diff line number Diff line change @@ -101,3 +101,22 @@ pub unsafe fn exchange_free_(ptr: *c_char) {
101
101
pub unsafe fn exchange_free ( ptr : * c_char ) {
102
102
free ( ptr as * c_void ) ;
103
103
}
104
+
105
+ #[ cfg( test) ]
106
+ mod bench {
107
+ use extra:: test:: BenchHarness ;
108
+
109
+ #[ bench]
110
+ fn alloc_owned_small ( bh : & mut BenchHarness ) {
111
+ do bh. iter {
112
+ ~10 ;
113
+ }
114
+ }
115
+
116
+ #[ bench]
117
+ fn alloc_owned_big ( bh : & mut BenchHarness ) {
118
+ do bh. iter {
119
+ ~[ 10 , ..1000 ] ;
120
+ }
121
+ }
122
+ }
Original file line number Diff line number Diff line change @@ -135,3 +135,22 @@ extern {
135
135
fn rust_boxed_region_free ( region : * BoxedRegion , box : * OpaqueBox ) ;
136
136
fn rust_current_boxed_region ( ) -> * BoxedRegion ;
137
137
}
138
+
139
+ #[ cfg( test) ]
140
+ mod bench {
141
+ use extra:: test:: BenchHarness ;
142
+
143
+ #[ bench]
144
+ fn alloc_managed_small ( bh : & mut BenchHarness ) {
145
+ do bh. iter {
146
+ @10 ;
147
+ }
148
+ }
149
+
150
+ #[ bench]
151
+ fn alloc_managed_big ( bh : & mut BenchHarness ) {
152
+ do bh. iter {
153
+ @[ 10 , ..1000 ] ;
154
+ }
155
+ }
156
+ }
Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ they contained the following prologue:
63
63
#[ deny( non_camel_case_types) ] ;
64
64
#[ deny( missing_doc) ] ;
65
65
66
+ // Make extra accessible for benchmarking
67
+ #[ cfg( test) ] extern mod extra ( vers="0.8-pre" ) ;
68
+
66
69
// Make std testable by not duplicating lang items. See #2912
67
70
#[ cfg( test) ] extern mod realstd ( name = "std" ) ;
68
71
#[ cfg( test) ] pub use kinds = realstd:: kinds;
Original file line number Diff line number Diff line change @@ -3532,3 +3532,50 @@ mod tests {
3532
3532
assert_eq!(5, sum_len([s.as_slice()]));
3533
3533
}
3534
3534
}
3535
+
3536
+ #[cfg(test)]
3537
+ mod bench {
3538
+ use extra::test::BenchHarness;
3539
+ use str;
3540
+
3541
+ #[bench]
3542
+ fn is_utf8_100_ascii(bh: &mut BenchHarness) {
3543
+
3544
+ let s = bytes!(" Hello there, the quick brown fox jumped over the lazy dog! \
3545
+ Lorem ipsum dolor sit amet, consectetur. ");
3546
+
3547
+ assert_eq!(100, s.len());
3548
+ do bh.iter {
3549
+ str::is_utf8(s);
3550
+ }
3551
+ }
3552
+
3553
+ #[bench]
3554
+ fn is_utf8_100_multibyte(bh: &mut BenchHarness) {
3555
+ let s = bytes!(" 𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
3556
+ assert_eq!(100, s.len());
3557
+ do bh.iter {
3558
+ str::is_utf8(s);
3559
+ }
3560
+ }
3561
+
3562
+ #[bench]
3563
+ fn map_chars_100_ascii(bh: &mut BenchHarness) {
3564
+ let s = " HelloHelloHelloHelloHelloHelloHelloHelloHelloHello \
3565
+ HelloHelloHelloHelloHelloHelloHelloHelloHelloHello ";
3566
+ do bh.iter {
3567
+ s.map_chars(|c| ((c as uint) + 1) as char);
3568
+ }
3569
+ }
3570
+
3571
+ #[bench]
3572
+ fn map_chars_100_multibytes(bh: &mut BenchHarness) {
3573
+ let s = " 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑\
3574
+ 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑\
3575
+ 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑\
3576
+ 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑" ;
3577
+ do bh. iter {
3578
+ s. map_chars( |c| ( ( c as uint) + 1 ) as char ) ;
3579
+ }
3580
+ }
3581
+ }
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
+ }
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ class cratemap {
68
68
return &reinterpret_cast <const cratemap_v0 *>(this )->
69
69
m_children[0 ];
70
70
case 1 :
71
- return &m_children[1 ];
71
+ return &m_children[0 ];
72
72
default : assert (false && " Unknown crate map version!" );
73
73
return NULL ; // Appease -Werror=return-type
74
74
}
You can’t perform that action at this time.
0 commit comments