@@ -9,60 +9,35 @@ use std::io::{self, Read, Write};
9
9
macro_rules! bench {
10
10
{
11
11
name: $name: expr,
12
+ bench: $bench: ident,
12
13
$( $args: tt) *
13
14
} => {
14
15
let name = format!( " {} " , $name) ;
15
16
println!( "\n {:=^26} parse|stringify ===== parse|stringify ====" , name) ;
16
17
17
18
#[ cfg( feature = "file-canada" ) ]
18
- bench_file ! {
19
+ $bench ! {
19
20
path: "data/canada.json" ,
20
21
structure: canada:: Canada ,
21
22
$( $args) *
22
23
}
23
24
24
25
#[ cfg( feature = "file-citm-catalog" ) ]
25
- bench_file ! {
26
+ $bench ! {
26
27
path: "data/citm_catalog.json" ,
27
28
structure: citm_catalog:: CitmCatalog ,
28
29
$( $args) *
29
30
}
30
31
31
32
#[ cfg( feature = "file-twitter" ) ]
32
- bench_file ! {
33
+ $bench ! {
33
34
path: "data/twitter.json" ,
34
35
structure: twitter:: Twitter ,
35
36
$( $args) *
36
37
}
37
38
}
38
39
}
39
40
40
- #[ cfg( feature = "lib-simd-json" ) ]
41
- macro_rules! bench_simd_json {
42
- { } => {
43
- let name = format!( " simd_json " ) ;
44
- println!( "\n {:=^26} parse|stringify ===== parse|stringify ====" , name) ;
45
-
46
- #[ cfg( feature = "file-canada" ) ]
47
- bench_file_simd_json! {
48
- path: "data/canada.json" ,
49
- structure: canada:: Canada ,
50
- }
51
-
52
- #[ cfg( feature = "file-citm-catalog" ) ]
53
- bench_file_simd_json! {
54
- path: "data/citm_catalog.json" ,
55
- structure: citm_catalog:: CitmCatalog ,
56
- }
57
-
58
- #[ cfg( feature = "file-twitter" ) ]
59
- bench_file_simd_json! {
60
- path: "data/twitter.json" ,
61
- structure: twitter:: Twitter ,
62
- }
63
- }
64
- }
65
-
66
41
macro_rules! bench_file {
67
42
{
68
43
path: $path: expr,
@@ -144,6 +119,10 @@ macro_rules! bench_file {
144
119
}
145
120
}
146
121
122
+ // This library is handled separately because simd-json needs to mutate its
123
+ // input unlike the other libraries. While this makes little difference in a
124
+ // real life situation as you're unlikely to deserialize the same data twice,
125
+ // it can be a disadvantage in a benchmark.
147
126
#[ cfg( feature = "lib-simd-json" ) ]
148
127
macro_rules! bench_file_simd_json {
149
128
{
@@ -241,6 +220,7 @@ fn main() {
241
220
#[ cfg( feature = "lib-serde" ) ]
242
221
bench ! {
243
222
name: "serde_json" ,
223
+ bench: bench_file,
244
224
dom: serde_json:: Value ,
245
225
parse_dom: serde_json_parse_dom,
246
226
stringify_dom: serde_json:: to_writer,
@@ -251,6 +231,7 @@ fn main() {
251
231
#[ cfg( feature = "lib-json-rust" ) ]
252
232
bench ! {
253
233
name: "json-rust" ,
234
+ bench: bench_file,
254
235
dom: json:: JsonValue ,
255
236
parse_dom: json_rust_parse_dom,
256
237
stringify_dom: json_rust_stringify_dom,
@@ -259,25 +240,19 @@ fn main() {
259
240
#[ cfg( feature = "lib-rustc-serialize" ) ]
260
241
bench ! {
261
242
name: "rustc_serialize" ,
243
+ bench: bench_file,
262
244
dom: rustc_serialize:: json:: Json ,
263
245
parse_dom: rustc_serialize_parse_dom,
264
246
stringify_dom: rustc_serialize_stringify,
265
247
parse_struct: rustc_serialize_parse_struct,
266
248
stringify_struct: rustc_serialize_stringify,
267
249
}
268
250
269
- // This is rolled out since simd-json does mutate
270
- // its input unlike the other libraries.
271
- // While this makes little difference in a real life situation
272
- // as you're unlikely to deserialize the same data twice
273
- // it is a big disadvantage in a synthetic benchmark.
274
- //
275
- // To be fair to both other libraries and simd-json
276
- // we roll it out and provide the same benchmarks
277
- // with slightly different characteristics.
278
-
279
251
#[ cfg( feature = "lib-simd-json" ) ]
280
- bench_simd_json ! { }
252
+ bench ! {
253
+ name: "simd_json" ,
254
+ bench: bench_file_simd_json,
255
+ }
281
256
}
282
257
283
258
#[ cfg( all(
0 commit comments