-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlib.rs
53 lines (45 loc) · 1.6 KB
/
lib.rs
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
#![feature(test)]
extern crate test;
extern crate resp;
use test::Bencher;
use std::io::BufReader;
use resp::{Value, Decoder};
fn prepare_values() -> Value {
let a = vec![Value::Null,
Value::NullArray,
Value::String("OKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOK"
.to_string()),
Value::Error("ErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErr"
.to_string()),
Value::Integer(1234567890),
Value::Bulk("Bulk String Bulk String Bulk String Bulk String Bulk String Bulk String"
.to_string()),
Value::Array(vec![Value::Null,
Value::Integer(123),
Value::Bulk("Bulk String Bulk String".to_string())])];
let mut b = a.clone();
b.push(Value::Array(a));
b.push(Value::Null);
let mut a = b.clone();
a.push(Value::Array(b));
a.push(Value::Null);
Value::Array(a)
}
// Last result:
// test decode_values ... bench: 6,298 ns/iter (+/- 5,783)
// test encode_values ... bench: 2,568 ns/iter (+/- 1,879)
#[bench]
fn encode_values(b: &mut Bencher) {
let value = prepare_values();
b.iter(|| value.encode());
}
#[bench]
fn decode_values(b: &mut Bencher) {
let value = prepare_values();
let buf = value.encode();
b.iter(|| {
let mut decoder = Decoder::new(BufReader::new(buf.as_slice()));
assert_eq!(decoder.decode().unwrap(), value);
assert!(decoder.decode().is_err());
});
}