Black box json benchmark numbers
This prevents the optimizer from optimizing away the thing we're benchmarking.
This commit is contained in:
parent
fe20852b2c
commit
4f6b27eec1
@ -1,6 +1,6 @@
|
||||
use std::io::{self, Read, Write};
|
||||
use num::FromPrimitive;
|
||||
use test::Bencher;
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
use rustc_serialize;
|
||||
|
||||
@ -1093,7 +1093,7 @@ fn test_encoder() {
|
||||
|
||||
{
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
log.encode(&mut encoder).unwrap();
|
||||
log.encode(&mut encoder).unwrap()
|
||||
}
|
||||
|
||||
assert_eq!(&wr, &JSON_STR);
|
||||
@ -1116,7 +1116,7 @@ fn bench_encoder(b: &mut Bencher) {
|
||||
wr.clear();
|
||||
|
||||
let mut encoder = rustc_serialize::json::Encoder::new(&mut wr);
|
||||
log.encode(&mut encoder).unwrap();
|
||||
log.encode(&mut encoder).unwrap()
|
||||
});
|
||||
}
|
||||
|
||||
@ -1134,7 +1134,7 @@ fn bench_serializer(b: &mut Bencher) {
|
||||
b.bytes = json.len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
serde_json::to_vec(&log).unwrap();
|
||||
serde_json::to_vec(&log).unwrap()
|
||||
});
|
||||
}
|
||||
|
||||
@ -1162,7 +1162,8 @@ fn bench_serializer_vec(b: &mut Bencher) {
|
||||
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1180,7 +1181,8 @@ fn bench_serializer_slice(b: &mut Bencher) {
|
||||
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1193,7 +1195,8 @@ fn test_serializer_my_mem_writer0() {
|
||||
{
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
}
|
||||
|
||||
assert_eq!(&wr.buf, &JSON_STR.as_bytes());
|
||||
@ -1212,7 +1215,8 @@ fn bench_serializer_my_mem_writer0(b: &mut Bencher) {
|
||||
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1225,7 +1229,8 @@ fn test_serializer_my_mem_writer1() {
|
||||
{
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
}
|
||||
|
||||
assert_eq!(&wr.buf, &JSON_STR.as_bytes());
|
||||
@ -1244,7 +1249,8 @@ fn bench_serializer_my_mem_writer1(b: &mut Bencher) {
|
||||
|
||||
let mut serializer = serde_json::Serializer::new(wr.by_ref());
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.into_inner();
|
||||
let json = serializer.into_inner();
|
||||
black_box(json);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1254,7 +1260,7 @@ fn bench_copy(b: &mut Bencher) {
|
||||
b.bytes = json.len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let _json = JSON_STR.as_bytes().to_vec();
|
||||
JSON_STR.as_bytes().to_vec()
|
||||
});
|
||||
}
|
||||
|
||||
@ -1441,7 +1447,7 @@ fn bench_manual_serialize_vec_no_escape(b: &mut Bencher) {
|
||||
|
||||
b.iter(|| {
|
||||
wr.clear();
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
manual_serialize_no_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1467,7 +1473,7 @@ fn bench_manual_serialize_vec_escape(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
wr.clear();
|
||||
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
manual_serialize_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1493,7 +1499,7 @@ fn bench_manual_serialize_my_mem_writer0_no_escape(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
wr.buf.clear();
|
||||
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
manual_serialize_no_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1519,7 +1525,7 @@ fn bench_manual_serialize_my_mem_writer0_escape(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
wr.buf.clear();
|
||||
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
manual_serialize_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1545,7 +1551,7 @@ fn bench_manual_serialize_my_mem_writer1_no_escape(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
wr.buf.clear();
|
||||
|
||||
manual_serialize_no_escape(&mut wr, &log);
|
||||
manual_serialize_no_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1571,7 +1577,7 @@ fn bench_manual_serialize_my_mem_writer1_escape(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
wr.buf.clear();
|
||||
|
||||
manual_serialize_escape(&mut wr, &log);
|
||||
manual_serialize_escape(&mut wr, &log)
|
||||
});
|
||||
}
|
||||
|
||||
@ -1584,7 +1590,8 @@ fn bench_decoder(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let json = Json::from_str(JSON_STR).unwrap();
|
||||
let mut decoder = rustc_serialize::json::Decoder::new(json);
|
||||
let _log: Log = rustc_serialize::Decodable::decode(&mut decoder).unwrap();
|
||||
let log: Log = rustc_serialize::Decodable::decode(&mut decoder).unwrap();
|
||||
log
|
||||
});
|
||||
}
|
||||
|
||||
@ -1593,6 +1600,7 @@ fn bench_deserializer(b: &mut Bencher) {
|
||||
b.bytes = JSON_STR.len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let _log: Log = serde_json::from_str(JSON_STR).unwrap();
|
||||
let log: Log = serde_json::from_str(JSON_STR).unwrap();
|
||||
log
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user