• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![feature(test)]
2 extern crate test;
3 
4 use std::io::Write;
5 use test::Bencher;
6 use uuid::Uuid;
7 
8 #[bench]
bench_hyphen(b: &mut Bencher)9 fn bench_hyphen(b: &mut Bencher) {
10     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
11     b.iter(|| {
12         let mut buffer = [0_u8; 36];
13         write!(&mut buffer as &mut [_], "{:x}", uuid.to_hyphenated()).unwrap();
14         test::black_box(buffer);
15     });
16 }
17 
18 #[bench]
bench_simple(b: &mut Bencher)19 fn bench_simple(b: &mut Bencher) {
20     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
21     b.iter(|| {
22         let mut buffer = [0_u8; 32];
23         write!(&mut buffer as &mut [_], "{:x}", uuid.to_simple()).unwrap();
24         test::black_box(buffer);
25     })
26 }
27 
28 #[bench]
bench_urn(b: &mut Bencher)29 fn bench_urn(b: &mut Bencher) {
30     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
31     b.iter(|| {
32         let mut buffer = [0_u8; 36 + 9];
33         write!(&mut buffer as &mut [_], "{:x}", uuid.to_urn()).unwrap();
34         test::black_box(buffer);
35     })
36 }
37 
38 #[bench]
bench_encode_hyphen(b: &mut Bencher)39 fn bench_encode_hyphen(b: &mut Bencher) {
40     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
41     b.iter(|| {
42         let mut buffer = [0_u8; 36];
43         uuid.to_hyphenated().encode_lower(&mut buffer);
44         test::black_box(buffer);
45     });
46 }
47 
48 #[bench]
bench_encode_simple(b: &mut Bencher)49 fn bench_encode_simple(b: &mut Bencher) {
50     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
51     b.iter(|| {
52         let mut buffer = [0_u8; 32];
53         uuid.to_simple().encode_lower(&mut buffer);
54         test::black_box(buffer);
55     })
56 }
57 
58 #[bench]
bench_encode_urn(b: &mut Bencher)59 fn bench_encode_urn(b: &mut Bencher) {
60     let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap();
61     b.iter(|| {
62         let mut buffer = [0_u8; 36 + 9];
63         uuid.to_urn().encode_lower(&mut buffer);
64         test::black_box(buffer);
65     })
66 }
67