Skip to content

Commit

Permalink
rewrote a benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mateocabanal committed Nov 21, 2023
1 parent 21c5799 commit fa2cff9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 288 deletions.
3 changes: 3 additions & 0 deletions tinyhttp-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ async = ["dep:tokio"]
ssl = ["dep:openssl"]
sys = ["ssl", "dep:flate2"]
log = ["dep:log"]

[dev-dependencies]
criterion = "0.5.1"
6 changes: 3 additions & 3 deletions tinyhttp-internal/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
#[cfg(feature = "sys")]
use flate2::{write::GzEncoder, Compression};

pub(crate) fn start_http(http: HttpListener, config: Config) {
pub fn start_http(http: HttpListener, config: Config) {
let arc_config = Arc::new(config);
for stream in http.get_stream() {
let mut conn = stream.unwrap();
Expand Down Expand Up @@ -264,7 +264,7 @@ fn build_res(mut req: Request, config: &Config) -> Response {
}
}

fn parse_request<P: Read + Write>(conn: &mut P, config: Arc<Config>) {
pub fn parse_request<P: Read + Write>(conn: &mut P, config: Arc<Config>) {
let buf = read_stream(conn);
let request = build_and_parse_req(buf);

Expand Down Expand Up @@ -372,7 +372,7 @@ fn parse_request<P: Read + Write>(conn: &mut P, config: Arc<Config>) {
response.send(conn);
}

pub fn read_to_vec<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
fn read_to_vec<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
fn inner(path: &Path) -> io::Result<Vec<u8>> {
let file = File::open(path).unwrap();
let mut content: Vec<u8> = Vec::new();
Expand Down
3 changes: 3 additions & 0 deletions tinyhttp-internal/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ impl Response {
]
.concat();

#[cfg(feature = "log")]
log::trace!("size of response: {}", full_req.len());

sock.write_all(full_req).unwrap();
}

Expand Down
Loading

0 comments on commit fa2cff9

Please sign in to comment.