forked from hyperium/hyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(body): remove stream cargo feature
remove stream cargo feature and any usage of stream, as it isn't stable and shouldn't be depended on closes issue hyperium#2855
- Loading branch information
Showing
14 changed files
with
536 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,88 @@ | ||
#![feature(test)] | ||
#![deny(warnings)] | ||
// #![feature(test)] | ||
// #![deny(warnings)] | ||
|
||
extern crate test; | ||
// extern crate test; | ||
|
||
use bytes::Buf; | ||
use futures_util::stream; | ||
use futures_util::StreamExt; | ||
use hyper::body::Body; | ||
// use bytes::Buf; | ||
// use futures_util::stream; | ||
// use futures_util::StreamExt; | ||
// use hyper::body::Body; | ||
|
||
macro_rules! bench_stream { | ||
($bencher:ident, bytes: $bytes:expr, count: $count:expr, $total_ident:ident, $body_pat:pat, $block:expr) => {{ | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.expect("rt build"); | ||
// macro_rules! bench_stream { | ||
// ($bencher:ident, bytes: $bytes:expr, count: $count:expr, $total_ident:ident, $body_pat:pat, $block:expr) => {{ | ||
// let rt = tokio::runtime::Builder::new_current_thread() | ||
// .build() | ||
// .expect("rt build"); | ||
|
||
let $total_ident: usize = $bytes * $count; | ||
$bencher.bytes = $total_ident as u64; | ||
let __s: &'static [&'static [u8]] = &[&[b'x'; $bytes] as &[u8]; $count] as _; | ||
// let $total_ident: usize = $bytes * $count; | ||
// $bencher.bytes = $total_ident as u64; | ||
// let __s: &'static [&'static [u8]] = &[&[b'x'; $bytes] as &[u8]; $count] as _; | ||
|
||
$bencher.iter(|| { | ||
rt.block_on(async { | ||
let $body_pat = Body::wrap_stream( | ||
stream::iter(__s.iter()).map(|&s| Ok::<_, std::convert::Infallible>(s)), | ||
); | ||
$block; | ||
}); | ||
}); | ||
}}; | ||
} | ||
// $bencher.iter(|| { | ||
// rt.block_on(async { | ||
// let $body_pat = | ||
// stream::iter(__s.iter()).map(|&s| Ok::<_, std::convert::Infallible>(s)); | ||
|
||
macro_rules! benches { | ||
($($name:ident, $bytes:expr, $count:expr;)+) => ( | ||
mod aggregate { | ||
use super::*; | ||
// $block; | ||
// }); | ||
// }); | ||
// }}; | ||
// } | ||
|
||
$( | ||
#[bench] | ||
fn $name(b: &mut test::Bencher) { | ||
bench_stream!(b, bytes: $bytes, count: $count, total, body, { | ||
let buf = hyper::body::aggregate(body).await.unwrap(); | ||
assert_eq!(buf.remaining(), total); | ||
}); | ||
} | ||
)+ | ||
} | ||
// macro_rules! benches { | ||
// ($($name:ident, $bytes:expr, $count:expr;)+) => ( | ||
// mod aggregate { | ||
// use super::*; | ||
|
||
mod manual_into_vec { | ||
use super::*; | ||
// $( | ||
// #[bench] | ||
// fn $name(b: &mut test::Bencher) { | ||
// bench_stream!(b, bytes: $bytes, count: $count, total, body, { | ||
// let buf = hyper::body::aggregate(body).await.unwrap(); | ||
// assert_eq!(buf.remaining(), total); | ||
// }); | ||
// } | ||
// )+ | ||
// } | ||
|
||
$( | ||
#[bench] | ||
fn $name(b: &mut test::Bencher) { | ||
bench_stream!(b, bytes: $bytes, count: $count, total, mut body, { | ||
let mut vec = Vec::new(); | ||
while let Some(chunk) = body.next().await { | ||
vec.extend_from_slice(&chunk.unwrap()); | ||
} | ||
assert_eq!(vec.len(), total); | ||
}); | ||
} | ||
)+ | ||
} | ||
// mod manual_into_vec { | ||
// use super::*; | ||
|
||
mod to_bytes { | ||
use super::*; | ||
// $( | ||
// #[bench] | ||
// fn $name(b: &mut test::Bencher) { | ||
// bench_stream!(b, bytes: $bytes, count: $count, total, mut body, { | ||
// let mut vec = Vec::new(); | ||
// while let Some(chunk) = body.next().await { | ||
// vec.extend_from_slice(&chunk.unwrap()); | ||
// } | ||
// assert_eq!(vec.len(), total); | ||
// }); | ||
// } | ||
// )+ | ||
// } | ||
|
||
$( | ||
#[bench] | ||
fn $name(b: &mut test::Bencher) { | ||
bench_stream!(b, bytes: $bytes, count: $count, total, body, { | ||
let bytes = hyper::body::to_bytes(body).await.unwrap(); | ||
assert_eq!(bytes.len(), total); | ||
}); | ||
} | ||
)+ | ||
} | ||
) | ||
} | ||
// mod to_bytes { | ||
// use super::*; | ||
|
||
// ===== Actual Benchmarks ===== | ||
// $( | ||
// #[bench] | ||
// fn $name(b: &mut test::Bencher) { | ||
// bench_stream!(b, bytes: $bytes, count: $count, total, body, { | ||
// let bytes = hyper::body::to_bytes(body).await.unwrap(); | ||
// assert_eq!(bytes.len(), total); | ||
// }); | ||
// } | ||
// )+ | ||
// } | ||
// ) | ||
// } | ||
|
||
benches! { | ||
bytes_1_000_count_2, 1_000, 2; | ||
bytes_1_000_count_10, 1_000, 10; | ||
bytes_10_000_count_1, 10_000, 1; | ||
bytes_10_000_count_10, 10_000, 10; | ||
} | ||
// // ===== Actual Benchmarks ===== | ||
|
||
// benches! { | ||
// bytes_1_000_count_2, 1_000, 2; | ||
// bytes_1_000_count_10, 1_000, 10; | ||
// bytes_10_000_count_1, 10_000, 1; | ||
// bytes_10_000_count_10, 10_000, 10; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.