Update to rust nightly
This commit is contained in:
parent
1ba0603273
commit
bc92cb884c
@ -590,170 +590,6 @@ impl Writer for MyMemWriter1 {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MyMemWriter2 {
|
||||
buf: Vec<u8>,
|
||||
pos: uint,
|
||||
}
|
||||
|
||||
impl MyMemWriter2 {
|
||||
/// Create a new `MemWriter`.
|
||||
#[inline]
|
||||
pub fn new() -> MyMemWriter2 {
|
||||
MyMemWriter2::with_capacity(128)
|
||||
}
|
||||
/// Create a new `MemWriter`, allocating at least `n` bytes for
|
||||
/// the internal buffer.
|
||||
#[inline]
|
||||
pub fn with_capacity(n: uint) -> MyMemWriter2 {
|
||||
MyMemWriter2 { buf: Vec::with_capacity(n), pos: 0 }
|
||||
}
|
||||
|
||||
/// Acquires an immutable reference to the underlying buffer of this
|
||||
/// `MemWriter`.
|
||||
///
|
||||
/// No method is exposed for acquiring a mutable reference to the buffer
|
||||
/// because it could corrupt the state of this `MemWriter`.
|
||||
#[inline]
|
||||
pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
|
||||
|
||||
/// Unwraps this `MemWriter`, returning the underlying buffer
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> Vec<u8> { self.buf }
|
||||
}
|
||||
|
||||
impl Writer for MyMemWriter2 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
if self.pos != self.buf.len() {
|
||||
push_all_bytes(&mut self.buf, buf);
|
||||
} else {
|
||||
// Make sure the internal buffer is as least as big as where we
|
||||
// currently are
|
||||
let difference = self.pos as i64 - self.buf.len() as i64;
|
||||
if difference > 0 {
|
||||
self.buf.grow(difference as uint, &0);
|
||||
}
|
||||
|
||||
// Figure out what bytes will be used to overwrite what's currently
|
||||
// there (left), and what will be appended on the end (right)
|
||||
let cap = self.buf.len() - self.pos;
|
||||
let (left, right) = if cap <= buf.len() {
|
||||
(buf.slice_to(cap), buf.slice_from(cap))
|
||||
} else {
|
||||
(buf, &[])
|
||||
};
|
||||
|
||||
// Do the necessary writes
|
||||
if left.len() > 0 {
|
||||
::std::slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left);
|
||||
}
|
||||
if right.len() > 0 {
|
||||
push_all_bytes(&mut self.buf, right);
|
||||
}
|
||||
}
|
||||
|
||||
// Bump us forward
|
||||
self.pos += buf.len();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn combine(seek: io::SeekStyle, cur: uint, end: uint, offset: i64) -> io::IoResult<u64> {
|
||||
// compute offset as signed and clamp to prevent overflow
|
||||
let pos = match seek {
|
||||
io::SeekSet => 0,
|
||||
io::SeekEnd => end,
|
||||
io::SeekCur => cur,
|
||||
} as i64;
|
||||
|
||||
if offset + pos < 0 {
|
||||
Err(io::IoError {
|
||||
kind: io::InvalidInput,
|
||||
desc: "invalid seek to a negative offset",
|
||||
detail: None
|
||||
})
|
||||
} else {
|
||||
Ok((offset + pos) as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl Seek for MyMemWriter2 {
|
||||
#[inline]
|
||||
fn tell(&self) -> io::IoResult<u64> { Ok(self.pos as u64) }
|
||||
|
||||
#[inline]
|
||||
fn seek(&mut self, pos: i64, style: io::SeekStyle) -> io::IoResult<()> {
|
||||
let new = try!(combine(style, self.pos, self.buf.len(), pos));
|
||||
self.pos = new as uint;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct MyMemWriter3 {
|
||||
buf: Vec<u8>,
|
||||
pos: uint,
|
||||
}
|
||||
|
||||
impl MyMemWriter3 {
|
||||
/// Create a new `MemWriter`.
|
||||
#[inline]
|
||||
pub fn new() -> MyMemWriter3 {
|
||||
MyMemWriter3::with_capacity(128)
|
||||
}
|
||||
/// Create a new `MemWriter`, allocating at least `n` bytes for
|
||||
/// the internal buffer.
|
||||
#[inline]
|
||||
pub fn with_capacity(n: uint) -> MyMemWriter3 {
|
||||
MyMemWriter3 { buf: Vec::with_capacity(n), pos: 0 }
|
||||
}
|
||||
|
||||
/// Acquires an immutable reference to the underlying buffer of this
|
||||
/// `MemWriter`.
|
||||
///
|
||||
/// No method is exposed for acquiring a mutable reference to the buffer
|
||||
/// because it could corrupt the state of this `MemWriter`.
|
||||
#[inline]
|
||||
pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
|
||||
|
||||
/// Unwraps this `MemWriter`, returning the underlying buffer
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> Vec<u8> { self.buf }
|
||||
}
|
||||
|
||||
impl Writer for MyMemWriter3 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
// Make sure the internal buffer is as least as big as where we
|
||||
// currently are
|
||||
let difference = self.pos as i64 - self.buf.len() as i64;
|
||||
if difference > 0 {
|
||||
self.buf.grow(difference as uint, &0);
|
||||
}
|
||||
|
||||
// Figure out what bytes will be used to overwrite what's currently
|
||||
// there (left), and what will be appended on the end (right)
|
||||
let cap = self.buf.len() - self.pos;
|
||||
let (left, right) = if cap <= buf.len() {
|
||||
(buf.slice_to(cap), buf.slice_from(cap))
|
||||
} else {
|
||||
(buf, &[])
|
||||
};
|
||||
|
||||
// Do the necessary writes
|
||||
if left.len() > 0 {
|
||||
::std::slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left);
|
||||
}
|
||||
if right.len() > 0 {
|
||||
push_all_bytes(&mut self.buf, right);
|
||||
}
|
||||
|
||||
// Bump us forward
|
||||
self.pos += buf.len();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_encoder(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
@ -822,36 +658,6 @@ fn bench_serializer_my_mem_writer1(b: &mut Bencher) {
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_serializer_my_mem_writer2(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let json = json::to_vec(&log);
|
||||
b.bytes = json.len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
//let _json = json::to_str(&log).unwrap();
|
||||
let wr = MyMemWriter2::with_capacity(1024);
|
||||
let mut serializer = json::Serializer::new(wr);
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.unwrap().unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_serializer_my_mem_writer3(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let json = json::to_vec(&log);
|
||||
b.bytes = json.len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
//let _json = json::to_str(&log).unwrap();
|
||||
let wr = MyMemWriter3::with_capacity(1024);
|
||||
let mut serializer = json::Serializer::new(wr);
|
||||
log.serialize(&mut serializer).unwrap();
|
||||
let _json = serializer.unwrap().unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_copy(b: &mut Bencher) {
|
||||
let s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
@ -1150,93 +956,6 @@ fn bench_manual_my_mem_writer1_escape(b: &mut Bencher) {
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer2_no_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter2::with_capacity(1000);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer2_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer3_no_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter3::with_capacity(1000);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer3_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
fn direct<W: Writer>(wr: W, log: &Log) {
|
||||
use serde::ser::Serializer;
|
||||
|
||||
|
@ -602,170 +602,6 @@ impl Writer for MyMemWriter1 {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MyMemWriter2 {
|
||||
buf: Vec<u8>,
|
||||
pos: uint,
|
||||
}
|
||||
|
||||
impl MyMemWriter2 {
|
||||
/// Create a new `MemWriter`.
|
||||
#[inline]
|
||||
pub fn new() -> MyMemWriter2 {
|
||||
MyMemWriter2::with_capacity(128)
|
||||
}
|
||||
/// Create a new `MemWriter`, allocating at least `n` bytes for
|
||||
/// the internal buffer.
|
||||
#[inline]
|
||||
pub fn with_capacity(n: uint) -> MyMemWriter2 {
|
||||
MyMemWriter2 { buf: Vec::with_capacity(n), pos: 0 }
|
||||
}
|
||||
|
||||
/// Acquires an immutable reference to the underlying buffer of this
|
||||
/// `MemWriter`.
|
||||
///
|
||||
/// No method is exposed for acquiring a mutable reference to the buffer
|
||||
/// because it could corrupt the state of this `MemWriter`.
|
||||
#[inline]
|
||||
pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
|
||||
|
||||
/// Unwraps this `MemWriter`, returning the underlying buffer
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> Vec<u8> { self.buf }
|
||||
}
|
||||
|
||||
impl Writer for MyMemWriter2 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
if self.pos != self.buf.len() {
|
||||
push_all_bytes(&mut self.buf, buf);
|
||||
} else {
|
||||
// Make sure the internal buffer is as least as big as where we
|
||||
// currently are
|
||||
let difference = self.pos as i64 - self.buf.len() as i64;
|
||||
if difference > 0 {
|
||||
self.buf.grow(difference as uint, &0);
|
||||
}
|
||||
|
||||
// Figure out what bytes will be used to overwrite what's currently
|
||||
// there (left), and what will be appended on the end (right)
|
||||
let cap = self.buf.len() - self.pos;
|
||||
let (left, right) = if cap <= buf.len() {
|
||||
(buf.slice_to(cap), buf.slice_from(cap))
|
||||
} else {
|
||||
(buf, &[])
|
||||
};
|
||||
|
||||
// Do the necessary writes
|
||||
if left.len() > 0 {
|
||||
::std::slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left);
|
||||
}
|
||||
if right.len() > 0 {
|
||||
push_all_bytes(&mut self.buf, right);
|
||||
}
|
||||
}
|
||||
|
||||
// Bump us forward
|
||||
self.pos += buf.len();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn combine(seek: io::SeekStyle, cur: uint, end: uint, offset: i64) -> io::IoResult<u64> {
|
||||
// compute offset as signed and clamp to prevent overflow
|
||||
let pos = match seek {
|
||||
io::SeekSet => 0,
|
||||
io::SeekEnd => end,
|
||||
io::SeekCur => cur,
|
||||
} as i64;
|
||||
|
||||
if offset + pos < 0 {
|
||||
Err(io::IoError {
|
||||
kind: io::InvalidInput,
|
||||
desc: "invalid seek to a negative offset",
|
||||
detail: None
|
||||
})
|
||||
} else {
|
||||
Ok((offset + pos) as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl Seek for MyMemWriter2 {
|
||||
#[inline]
|
||||
fn tell(&self) -> io::IoResult<u64> { Ok(self.pos as u64) }
|
||||
|
||||
#[inline]
|
||||
fn seek(&mut self, pos: i64, style: io::SeekStyle) -> io::IoResult<()> {
|
||||
let new = try!(combine(style, self.pos, self.buf.len(), pos));
|
||||
self.pos = new as uint;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct MyMemWriter3 {
|
||||
buf: Vec<u8>,
|
||||
pos: uint,
|
||||
}
|
||||
|
||||
impl MyMemWriter3 {
|
||||
/// Create a new `MemWriter`.
|
||||
#[inline]
|
||||
pub fn new() -> MyMemWriter3 {
|
||||
MyMemWriter3::with_capacity(128)
|
||||
}
|
||||
/// Create a new `MemWriter`, allocating at least `n` bytes for
|
||||
/// the internal buffer.
|
||||
#[inline]
|
||||
pub fn with_capacity(n: uint) -> MyMemWriter3 {
|
||||
MyMemWriter3 { buf: Vec::with_capacity(n), pos: 0 }
|
||||
}
|
||||
|
||||
/// Acquires an immutable reference to the underlying buffer of this
|
||||
/// `MemWriter`.
|
||||
///
|
||||
/// No method is exposed for acquiring a mutable reference to the buffer
|
||||
/// because it could corrupt the state of this `MemWriter`.
|
||||
#[inline]
|
||||
pub fn get_ref<'a>(&'a self) -> &'a [u8] { self.buf.as_slice() }
|
||||
|
||||
/// Unwraps this `MemWriter`, returning the underlying buffer
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> Vec<u8> { self.buf }
|
||||
}
|
||||
|
||||
impl Writer for MyMemWriter3 {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
|
||||
// Make sure the internal buffer is as least as big as where we
|
||||
// currently are
|
||||
let difference = self.pos as i64 - self.buf.len() as i64;
|
||||
if difference > 0 {
|
||||
self.buf.grow(difference as uint, &0);
|
||||
}
|
||||
|
||||
// Figure out what bytes will be used to overwrite what's currently
|
||||
// there (left), and what will be appended on the end (right)
|
||||
let cap = self.buf.len() - self.pos;
|
||||
let (left, right) = if cap <= buf.len() {
|
||||
(buf.slice_to(cap), buf.slice_from(cap))
|
||||
} else {
|
||||
(buf, &[])
|
||||
};
|
||||
|
||||
// Do the necessary writes
|
||||
if left.len() > 0 {
|
||||
::std::slice::bytes::copy_memory(self.buf.mut_slice_from(self.pos), left);
|
||||
}
|
||||
if right.len() > 0 {
|
||||
push_all_bytes(&mut self.buf, right);
|
||||
}
|
||||
|
||||
// Bump us forward
|
||||
self.pos += buf.len();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_encoder(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
@ -1090,93 +926,6 @@ fn bench_manual_my_mem_writer1_escape(b: &mut Bencher) {
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer2_no_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter2::with_capacity(1000);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer2_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter2::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer3_no_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter3::with_capacity(1000);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_no_escape(wr.by_ref(), &log);
|
||||
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_manual_my_mem_writer3_escape(b: &mut Bencher) {
|
||||
let log = Log::new();
|
||||
let _s = r#"{"timestamp":2837513946597,"zone_id":123456,"zone_plan":"FREE","http":{"protocol":"HTTP11","status":200,"host_status":503,"up_status":520,"method":"GET","content_type":"text/html","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36","referer":"https://www.cloudflare.com/","request_uri":"/cdn-cgi/trace"},"origin":{"ip":"1.2.3.4","port":8000,"hostname":"www.example.com","protocol":"HTTPS"},"country":"US","cache_status":"Hit","server_ip":"192.168.1.1","server_name":"metal.cloudflare.com","remote_ip":"10.1.2.3","bytes_dlv":123456,"ray_id":"10c73629cce30078-LAX"}"#;
|
||||
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
b.bytes = wr.unwrap().len() as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let mut wr = MyMemWriter3::with_capacity(1024);
|
||||
manual_escape(wr.by_ref(), &log);
|
||||
let _json = wr.unwrap();
|
||||
|
||||
//let _json = String::from_utf8(wr.unwrap()).unwrap();
|
||||
/*
|
||||
assert_eq!(_s, _json.as_slice());
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
fn direct<W: Writer>(wr: W, log: &Log) {
|
||||
use serde2::ser::VisitorState;
|
||||
|
@ -288,7 +288,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
struct Tuple2Serialize<'a, T0, T1> {
|
||||
struct Tuple2Serialize<'a, T0: 'a, T1: 'a> {
|
||||
value: &'a (T0, T1),
|
||||
state: uint,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user