1 use {
2     deser_hjson::from_str,
3     serde:: Deserialize,
4     glassbench::*,
5 };
6 
7 static GIFTS: &[&str] = &[
8     "{gift:null}",
9     "{gift:false}",
10     "{gift: true}",
11     "{gift:'bar'}",
12     r#"{gift:"bar"}"#,
13     "{gift:42}",
14     "{gift:42457811247}",
15     "{gift:-42}",
16     r#"{gift: "abcㅈ"}"#,
17     "{gift:[15, -50]}",
18     "{gift:[\"abc\"]}",
19     r#"{gift:["abc", "another string"]}"#,
20     r#" {
21         gift: [
22             "abc",
23             "another string"
24             and a third one (unquoted)
25         ]
26     }"#,
27     "{gift:''}",
28 ];
29 
30 #[derive(Deserialize, PartialEq, Debug)]
31 #[serde(untagged)]
32 enum Guess {
33     Bool(bool),
34     U8(u8),
35     I8(i8),
36     U16(u16),
37     I16(i16),
38     U32(u32),
39     I32(i32),
40     U64(u64),
41     I64(i64),
42     F64(f64),
43     Char(char),
44     String(Option<String>),
45     U16Array(Vec<u16>),
46     I16Array(Vec<i16>),
47     StrArray(Vec<String>),
48 }
49 #[derive(Deserialize, PartialEq, Debug)]
50 struct WrappedGuess {
51     gift: Guess,
52 }
53 
bench_parse(bench: &mut Bench)54 fn bench_parse(bench: &mut Bench) {
55     bench.task("guess wrapped", |task| {
56         task.iter(|| {
57             for hjson in GIFTS {
58                 let guessed = from_str::<WrappedGuess>(hjson)
59                     .unwrap_or_else(|e| panic!("Parsing failed for {:?} : {}", hjson, e));
60                 pretend_used(guessed);
61             }
62         });
63     });
64 }
65 glassbench!(
66     "Parse",
67     bench_parse,
68 );
69 
70