1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![feature(test)]
#![feature(never_type)]
#![feature(shrink_to)]
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#![feature(box_patterns)]
#![feature(slice_index_methods)]
#![feature(associated_type_defaults)]


extern crate test;
extern crate regex;
#[macro_use] extern crate nom;

pub mod json;
pub mod jq;
mod jqnom;
mod document;
mod lex;

#[cfg(test)]
mod tests {
    use test::Bencher;

    #[test]
    fn test_codepoint() {
        let s = "å".to_string();
        let mut chars = s.chars();
        assert_eq!('a', chars.next().unwrap());
        assert_eq!('\u{30a}', chars.next().unwrap());

        let mut s = String::new();
        s.push_str("\u{0061}");
        s.push_str("\u{030a}");
        assert_eq!("å", s);
    }

    #[bench]
    fn bench_string_copy_1_k(b: &mut Bencher) {
        let mut s = String::with_capacity(1000);
        let mut d = String::with_capacity(1000);
        let r = "helloworld";
        (1..100).for_each(|_| s.push_str(r));

        b.iter(|| {d.clone_from(&s); d.truncate(0)} );
    }

    #[bench]
    fn bench_string_copy_4_k(b: &mut Bencher) {
        let mut s = String::with_capacity(4000);
        let mut d = String::with_capacity(4000);
        let r = "helloworld";
        (1..400).for_each(|_| s.push_str(r));

        b.iter(|| {d.clone_from(&s); d.truncate(0)} );
    }

    #[bench]
    fn bench_string_copy_10_k(b: &mut Bencher) {
        let mut s = String::with_capacity(10000);
        let mut d = String::with_capacity(10000);
        let r = "helloworld";
        (1..1000).for_each(|_| s.push_str(r));

        b.iter(|| {d.clone_from(&s); d.truncate(0)} );
    }

    #[bench]
    fn bench_string_copy_1_m(b: &mut Bencher) {
        let mut s = String::with_capacity(1000000);
        let mut d = String::with_capacity(1000000);
        let r = "helloworld";
        (1..100000).for_each(|_| s.push_str(r));

        b.iter(|| {d.clone_from(&s); d.truncate(0)} );
    }
}