@@ -44,37 +44,37 @@ macro_rules! check_type (($name:ident, $x:expr, $p:pat) => (
44
44
_ => panic!( "atom has wrong type" ) ,
45
45
}
46
46
}
47
- ) )
47
+ ) ) ;
48
48
49
49
macro_rules! bench_tiny_op ( ( $name: ident, $op: ident, $ctor_x: expr, $ctor_y: expr) => (
50
50
#[ bench]
51
51
fn $name( b: & mut Bencher ) {
52
52
const n: uint = 1000 ;
53
- let xs = Vec :: from_elem ( n , $ctor_x) ;
54
- let ys = Vec :: from_elem ( n , $ctor_y) ;
53
+ let xs: Vec <_> = repeat ( $ctor_x) . take ( n ) . collect ( ) ;
54
+ let ys: Vec <_> = repeat ( $ctor_y) . take ( n ) . collect ( ) ;
55
55
56
56
b. iter( || {
57
57
for ( x, y) in xs. iter( ) . zip( ys. iter( ) ) {
58
58
black_box( x. $op( y) ) ;
59
59
}
60
60
} ) ;
61
61
}
62
- ) )
62
+ ) ) ;
63
63
64
64
macro_rules! bench_one (
65
- ( x_static $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Static ( ..) ) ) ;
66
- ( x_inline $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Inline ( ..) ) ) ;
67
- ( x_dynamic $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Dynamic ( ..) ) ) ;
68
- ( y_static $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Static ( ..) ) ) ;
69
- ( y_inline $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Inline ( ..) ) ) ;
70
- ( y_dynamic $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Dynamic ( ..) ) ) ;
71
- ( is_static $x: expr, $y: expr) => ( bench_one!( x_static $x, $y) bench_one!( y_static $x, $y) ) ;
72
- ( is_inline $x: expr, $y: expr) => ( bench_one!( x_inline $x, $y) bench_one!( y_inline $x, $y) ) ;
73
- ( is_dynamic $x: expr, $y: expr) => ( bench_one!( x_dynamic $x, $y) bench_one!( y_dynamic $x, $y) ) ;
74
-
75
- ( eq $x: expr, $_y: expr) => ( bench_tiny_op!( eq_x_1000, eq, $x, $x) ) ;
76
- ( ne $x: expr, $y: expr) => ( bench_tiny_op!( ne_x_1000, ne, $x, $y) ) ;
77
- ( lt $x: expr, $y: expr) => ( bench_tiny_op!( lt_x_1000, lt, $x, $y) ) ;
65
+ ( x_static $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Static ( ..) ) ; ) ;
66
+ ( x_inline $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Inline ( ..) ) ; ) ;
67
+ ( x_dynamic $x: expr, $y: expr) => ( check_type!( check_type_x, $x, Dynamic ( ..) ) ; ) ;
68
+ ( y_static $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Static ( ..) ) ; ) ;
69
+ ( y_inline $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Inline ( ..) ) ; ) ;
70
+ ( y_dynamic $x: expr, $y: expr) => ( check_type!( check_type_y, $y, Dynamic ( ..) ) ; ) ;
71
+ ( is_static $x: expr, $y: expr) => ( bench_one!( x_static $x, $y) ; bench_one!( y_static $x, $y) ; ) ;
72
+ ( is_inline $x: expr, $y: expr) => ( bench_one!( x_inline $x, $y) ; bench_one!( y_inline $x, $y) ; ) ;
73
+ ( is_dynamic $x: expr, $y: expr) => ( bench_one!( x_dynamic $x, $y) ; bench_one!( y_dynamic $x, $y) ; ) ;
74
+
75
+ ( eq $x: expr, $_y: expr) => ( bench_tiny_op!( eq_x_1000, eq, $x, $x) ; ) ;
76
+ ( ne $x: expr, $y: expr) => ( bench_tiny_op!( ne_x_1000, ne, $x, $y) ; ) ;
77
+ ( lt $x: expr, $y: expr) => ( bench_tiny_op!( lt_x_1000, lt, $x, $y) ; ) ;
78
78
79
79
( intern $x: expr, $_y: expr) => (
80
80
#[ bench]
@@ -122,7 +122,7 @@ macro_rules! bench_one (
122
122
} ) ;
123
123
}
124
124
) ;
125
- )
125
+ ) ;
126
126
127
127
macro_rules! bench_all (
128
128
( [ $( $which: ident) + ] for $name: ident = $x: expr, $y: expr) => (
@@ -135,61 +135,62 @@ macro_rules! bench_all (
135
135
use collections:: vec:: Vec ;
136
136
use test:: { Bencher , black_box} ;
137
137
use std:: string:: ToString ;
138
+ use std:: iter:: repeat;
138
139
139
140
use atom:: Atom ;
140
141
use atom:: repr:: { Static , Inline , Dynamic } ;
141
142
142
143
use super :: mk;
143
144
144
145
$(
145
- bench_one!( $which $x, $y)
146
+ bench_one!( $which $x, $y) ;
146
147
) +
147
148
}
148
149
) ;
149
- )
150
+ ) ;
150
151
151
152
pub const longer_dynamic_a: & ' static str
152
153
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Band" ;
153
154
pub const longer_dynamic_b: & ' static str
154
155
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Ban!" ;
155
156
156
- bench_all ! ( [ eq ne lt clone_string] for short_string = "e" , "f" )
157
- bench_all ! ( [ eq ne lt clone_string] for medium_string = "xyzzy01" , "xyzzy02" )
157
+ bench_all ! ( [ eq ne lt clone_string] for short_string = "e" , "f" ) ;
158
+ bench_all ! ( [ eq ne lt clone_string] for medium_string = "xyzzy01" , "xyzzy02" ) ;
158
159
bench_all ! ( [ eq ne lt clone_string]
159
- for longer_string = super :: longer_dynamic_a, super :: longer_dynamic_b)
160
+ for longer_string = super :: longer_dynamic_a, super :: longer_dynamic_b) ;
160
161
161
162
bench_all ! ( [ eq ne intern as_slice clone is_static lt]
162
- for static_atom = atom!( a) , atom!( b) )
163
+ for static_atom = atom!( a) , atom!( b) ) ;
163
164
164
165
bench_all ! ( [ intern as_slice clone is_inline]
165
- for short_inline_atom = mk( "e" ) , mk( "f" ) )
166
+ for short_inline_atom = mk( "e" ) , mk( "f" ) ) ;
166
167
167
168
bench_all ! ( [ eq ne intern as_slice clone is_inline lt]
168
- for medium_inline_atom = mk( "xyzzy01" ) , mk( "xyzzy02" ) )
169
+ for medium_inline_atom = mk( "xyzzy01" ) , mk( "xyzzy02" ) ) ;
169
170
170
171
bench_all ! ( [ intern as_slice clone is_dynamic]
171
- for min_dynamic_atom = mk( "xyzzy001" ) , mk( "xyzzy002" ) )
172
+ for min_dynamic_atom = mk( "xyzzy001" ) , mk( "xyzzy002" ) ) ;
172
173
173
174
bench_all ! ( [ eq ne intern as_slice clone is_dynamic lt]
174
- for longer_dynamic_atom = mk( super :: longer_dynamic_a) , mk( super :: longer_dynamic_b) )
175
+ for longer_dynamic_atom = mk( super :: longer_dynamic_a) , mk( super :: longer_dynamic_b) ) ;
175
176
176
177
bench_all ! ( [ intern as_slice clone is_static]
177
- for static_at_runtime = mk( "a" ) , mk( "b" ) )
178
+ for static_at_runtime = mk( "a" ) , mk( "b" ) ) ;
178
179
179
180
bench_all ! ( [ ne lt x_static y_inline]
180
- for static_vs_inline = atom!( a) , mk( "f" ) )
181
+ for static_vs_inline = atom!( a) , mk( "f" ) ) ;
181
182
182
183
bench_all ! ( [ ne lt x_static y_dynamic]
183
- for static_vs_dynamic = atom!( a) , mk( super :: longer_dynamic_b) )
184
+ for static_vs_dynamic = atom!( a) , mk( super :: longer_dynamic_b) ) ;
184
185
185
186
bench_all ! ( [ ne lt x_inline y_dynamic]
186
- for inline_vs_dynamic = mk( "e" ) , mk( super :: longer_dynamic_b) )
187
+ for inline_vs_dynamic = mk( "e" ) , mk( super :: longer_dynamic_b) ) ;
187
188
188
189
macro_rules! bench_rand ( ( $name: ident, $len: expr) => (
189
190
#[ bench]
190
191
fn $name( b: & mut Bencher ) {
191
192
use std:: { str , rand} ;
192
- use std:: slice:: { SlicePrelude , AsSlice } ;
193
+ use std:: slice:: { AsSlice , SliceExt } ;
193
194
use std:: rand:: Rng ;
194
195
195
196
let mut gen = rand:: weak_rng( ) ;
@@ -200,19 +201,19 @@ macro_rules! bench_rand ( ($name:ident, $len:expr) => (
200
201
// I measured the overhead of random string generation
201
202
// as about 3-12% at one point.
202
203
203
- let mut buf: [ u8 , .. $len] = [ 0 , .. $len] ;
204
+ let mut buf: [ u8 ; $len] = [ 0 ; $len] ;
204
205
gen . fill_bytes( buf. as_mut_slice( ) ) ;
205
206
for n in buf. iter_mut( ) {
206
207
// shift into printable ASCII
207
208
* n = ( * n % 0x40 ) + 0x20 ;
208
209
}
209
- let s = unsafe { str :: raw :: from_utf8( buf. as_slice( ) ) } ;
210
+ let s = str :: from_utf8( buf. as_slice( ) ) . unwrap ( ) ;
210
211
black_box( Atom :: from_slice( s) ) ;
211
212
} ) ;
212
213
}
213
- ) )
214
+ ) ) ;
214
215
215
- bench_rand ! ( intern_rand_008, 8 )
216
- bench_rand ! ( intern_rand_032, 32 )
217
- bench_rand ! ( intern_rand_128, 128 )
218
- bench_rand ! ( intern_rand_512, 512 )
216
+ bench_rand ! ( intern_rand_008, 8 ) ;
217
+ bench_rand ! ( intern_rand_032, 32 ) ;
218
+ bench_rand ! ( intern_rand_128, 128 ) ;
219
+ bench_rand ! ( intern_rand_512, 512 ) ;
0 commit comments