mirror of
https://github.com/fafhrd91/actix-web
synced 2025-02-20 03:14:21 +01:00
fix bench
This commit is contained in:
parent
2d11ab5977
commit
4431c8da65
@ -42,32 +42,37 @@ mod _new {
|
|||||||
if x < 10 {
|
if x < 10 {
|
||||||
f.write_str("00")?;
|
f.write_str("00")?;
|
||||||
// 0 is handled so it's not possible to have a trailing 0, we can just return
|
// 0 is handled so it's not possible to have a trailing 0, we can just return
|
||||||
itoa::fmt(f, x)
|
itoa_fmt(f, x)
|
||||||
} else if x < 100 {
|
} else if x < 100 {
|
||||||
f.write_str("0")?;
|
f.write_str("0")?;
|
||||||
if x % 10 == 0 {
|
if x % 10 == 0 {
|
||||||
// trailing 0, divide by 10 and write
|
// trailing 0, divide by 10 and write
|
||||||
itoa::fmt(f, x / 10)
|
itoa_fmt(f, x / 10)
|
||||||
} else {
|
} else {
|
||||||
itoa::fmt(f, x)
|
itoa_fmt(f, x)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// x is in range 101–999
|
// x is in range 101–999
|
||||||
|
|
||||||
if x % 100 == 0 {
|
if x % 100 == 0 {
|
||||||
// two trailing 0s, divide by 100 and write
|
// two trailing 0s, divide by 100 and write
|
||||||
itoa::fmt(f, x / 100)
|
itoa_fmt(f, x / 100)
|
||||||
} else if x % 10 == 0 {
|
} else if x % 10 == 0 {
|
||||||
// one trailing 0, divide by 10 and write
|
// one trailing 0, divide by 10 and write
|
||||||
itoa::fmt(f, x / 10)
|
itoa_fmt(f, x / 10)
|
||||||
} else {
|
} else {
|
||||||
itoa::fmt(f, x)
|
itoa_fmt(f, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn itoa_fmt<W: fmt::Write, V: itoa::Integer>(mut wr: W, value: V) -> fmt::Result {
|
||||||
|
let mut buf = itoa::Buffer::new();
|
||||||
|
wr.write_str(buf.format(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod _naive {
|
mod _naive {
|
||||||
|
@ -299,38 +299,6 @@ mod tests {
|
|||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[actix_rt::test]
|
|
||||||
// async fn test_data_factory() {
|
|
||||||
// let cfg = |cfg: &mut ServiceConfig| {
|
|
||||||
// cfg.data_factory(|| {
|
|
||||||
// sleep(std::time::Duration::from_millis(50)).then(|_| {
|
|
||||||
// println!("READY");
|
|
||||||
// Ok::<_, ()>(10usize)
|
|
||||||
// })
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let srv =
|
|
||||||
// init_service(App::new().configure(cfg).service(
|
|
||||||
// web::resource("/").to(|_: web::Data<usize>| HttpResponse::Ok()),
|
|
||||||
// ));
|
|
||||||
// let req = TestRequest::default().to_request();
|
|
||||||
// let resp = srv.call(req).await.unwrap();
|
|
||||||
// assert_eq!(resp.status(), StatusCode::OK);
|
|
||||||
|
|
||||||
// let cfg2 = |cfg: &mut ServiceConfig| {
|
|
||||||
// cfg.data_factory(|| Ok::<_, ()>(10u32));
|
|
||||||
// };
|
|
||||||
// let srv = init_service(
|
|
||||||
// App::new()
|
|
||||||
// .service(web::resource("/").to(|_: web::Data<usize>| HttpResponse::Ok()))
|
|
||||||
// .configure(cfg2),
|
|
||||||
// );
|
|
||||||
// let req = TestRequest::default().to_request();
|
|
||||||
// let resp = srv.call(req).await.unwrap();
|
|
||||||
// assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_external_resource() {
|
async fn test_external_resource() {
|
||||||
let srv = init_service(
|
let srv = init_service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user