Debian Codegraph @

third_party/rust/rmp/benches/bench.rs

raw
1 #![feature(test)]
2
3 extern crate test;
4
5 use test::Bencher;
6
7 use rmp::decode::*;
8
9 #[bench]
10 fn from_i64_read_i64(b: &mut Bencher) {
11 let buf = [0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
12
13 b.iter(|| {
14 let res = read_i64(&mut &buf[..]).unwrap();
15 test::black_box(res);
16 });
17 }
18
19 #[bench]
20 fn from_i64_read_int(b: &mut Bencher) {
21 let buf = [0xd3, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
22
23 b.iter(|| {
24 let res: i64 = read_int(&mut &buf[..]).unwrap();
25 test::black_box(res);
26 });
27 }
28
29 #[bench]
30 fn from_string_read_str(b: &mut Bencher) {
31 // Lorem ipsum dolor sit amet.
32 let buf = [
33 0xbb, 0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73,
34 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73,
35 0x69, 0x74, 0x20, 0x61, 0x6d, 0x65, 0x74, 0x2e
36 ];
37
38 let mut out = [0u8; 32];
39
40 b.iter(|| {
41 let res = read_str(&mut &buf[..], &mut out[..]).unwrap();
42 test::black_box(res);
43 });
44 }