fn async_web_service(c: &mut Criterion) {
    let rt = actix_rt::System::new();
    let srv = Rc::new(RefCell::new(rt.block_on(init_service(
        App::new().service(web::service("/").finish(index)),
    ))));

    let req = TestRequest::get().uri("/").to_request();
    assert!(rt
        .block_on(srv.borrow_mut().call(req))
        .unwrap()
        .status()
        .is_success());

    // start benchmark loops
    c.bench_function("async_web_service_direct", move |b| {
        b.iter_custom(|iters| {
            let srv = srv.clone();
            let futs = (0..iters)
                .map(|_| TestRequest::get().uri("/").to_request())
                .map(|req| srv.borrow_mut().call(req));
            let start = std::time::Instant::now();
            // benchmark body
            rt.block_on(async move {
                for fut in futs {
                    fut.await.unwrap();
                }
            });
            // check that at least first request succeeded
            start.elapsed()
        })
    });
}
// Benchmark basic WebService directly
// this approach is usable for benching WebService, though it adds some time to direct service call:
// Sample results on MacBook Pro '14
// time:   [2.0724 us 2.1345 us 2.2074 us]
Benchmark basic WebService directly
this approach is usable for benching WebService, though it adds some time to direct service call:
Sample results on MacBook Pro '14
time:   [2.0724 us 2.1345 us 2.2074 us]
Benchmark basic WebService directly this approach is usable for benching WebService though it adds some time to direct service call : Sample results on MacBook Pro ' 14 time : [ 2 . 0724 us 2 . 1345 us 2 . 2074 us ]
fn async_web_service(c: &mut Criterion) {
    let rt = actix_rt::System::new();
    let srv = Rc::new(RefCell::new(rt.block_on(init_service(
        App::new().service(web::service("/").finish(index)),
    ))));
    let req = TestRequest::get().uri("/").to_request();
    assert!(rt
        .block_on(srv.borrow_mut().call(req))
        .unwrap()
        .status()
        .is_success());
    // start benchmark loops
    c.bench_function("async_web_service_direct", move |b| {
        b.iter_custom(|iters| {
            let srv = srv.clone();
            let futs = (0..iters)
                .map(|_| TestRequest::get().uri("/").to_request())
                .map(|req| srv.borrow_mut().call(req));
            let start = std::time::Instant::now();
            // benchmark body
            rt.block_on(async move {
                for fut in futs {
                    fut.await.unwrap();
                }
            });
            // check that at least first request succeeded
            start.elapsed()
        })
    });
}
fn async_web_service ( c : & mut Criterion ) { let rt = actix_rt :: System :: new ( ) ; let srv = Rc :: new ( RefCell :: new ( rt . block_on ( init_service ( App :: new ( ) . service ( web :: service ( " " ) . finish ( index ) ) , ) ) ) ) ; let req = TestRequest :: get ( ) . uri ( " " ) . to_request ( ) ; assert ! ( rt block_on ( srv borrow_mut ( ) call ( req ) ) unwrap ( ) status ( ) is_success ( ) ) ; // start benchmark loops c . bench_function ( " " , move | b | { b . iter_custom ( | iters | { let srv = srv . clone ( ) ; let futs = ( 0 .. iters ) . map ( | _ | TestRequest :: get ( ) . uri ( " " ) . to_request ( ) ) . map ( | req | srv . borrow_mut ( ) . call ( req ) ) ; let start = std :: time :: Instant :: now ( ) ; // benchmark body rt . block_on ( async move { for fut in futs { fut . await . unwrap ( ) ; } } ) ; // check that at least first request succeeded start . elapsed ( ) } ) } ) ; }
Benchmark basic WebService directly
this approach is usable for benching WebService, though it adds some time to direct service call:
Sample results on MacBook Pro '14
time:   [2.0724 us 2.1345 us 2.2074 us]
Benchmark basic WebService directly this approach is usable for benching WebService though it adds some time to direct service call : Sample results on MacBook Pro ' 14 time : [ 2 . 0724 us 2 . 1345 us 2 . 2074 us ]
c
&mut Criterion
c
&mut Criterion