@@ -145,6 +145,29 @@ impl Template<ValueMap> for ValueMap {
145
145
}
146
146
}
147
147
148
+ type UsizeMap = BTreeMap < usize , usize > ;
149
+
150
+ /// Template for testing roughly a GraphQL response, i.e., a `BTreeMap<String, Value>`
151
+ impl Template < UsizeMap > for UsizeMap {
152
+ type Item = UsizeMap ;
153
+
154
+ fn create ( size : usize ) -> Self {
155
+ let mut map = BTreeMap :: new ( ) ;
156
+ for i in 0 ..size {
157
+ map. insert ( i * 2 , i * 3 ) ;
158
+ }
159
+ map
160
+ }
161
+
162
+ fn sample ( & self , size : usize ) -> Box < Self :: Item > {
163
+ Box :: new ( BTreeMap :: from_iter (
164
+ self . iter ( )
165
+ . take ( size)
166
+ . map ( |( k, v) | ( k. to_owned ( ) , v. to_owned ( ) ) ) ,
167
+ ) )
168
+ }
169
+ }
170
+
148
171
/// Helper to deal with different template objects
149
172
struct Cacheable < T > {
150
173
cache : LfuCache < usize , T > ,
@@ -172,10 +195,14 @@ impl<T: Template<T>> Cacheable<T> {
172
195
#[ derive( StructOpt ) ]
173
196
#[ structopt( name = "stress" , about = "Stress test for the LFU Cache" ) ]
174
197
struct Opt {
198
+ /// Number of cache evictions and insertions
175
199
#[ structopt( short, long, default_value = "1000" ) ]
176
200
niter : usize ,
201
+ /// Print this many intermediate messages
177
202
#[ structopt( short, long, default_value = "10" ) ]
178
203
print_count : usize ,
204
+ /// Use objects of size 0 up to this size, chosen unifromly randomly
205
+ /// unless `--fixed` is given
179
206
#[ structopt( short, long, default_value = "1024" ) ]
180
207
obj_size : usize ,
181
208
#[ structopt( short, long, default_value = "1000000" ) ]
@@ -184,6 +211,7 @@ struct Opt {
184
211
template : String ,
185
212
#[ structopt( short, long) ]
186
213
samples : bool ,
214
+ /// Always use objects of size `--obj-size`
187
215
#[ structopt( short, long) ]
188
216
fixed : bool ,
189
217
}
@@ -288,6 +316,8 @@ pub fn main() {
288
316
stress :: < ValueMap > ( & opt) ;
289
317
} else if opt. template == "string" {
290
318
stress :: < String > ( & opt) ;
319
+ } else if opt. template == "usizemap" {
320
+ stress :: < UsizeMap > ( & opt)
291
321
} else {
292
322
println ! ( "unknown value for --template" )
293
323
}
0 commit comments