Files
tarpc/benches/latency.rs
Tim Kuehn fe20c8af14 Add a reactor::Core field to SyncClient.
This allows the client to drive its own execution, as one would expect.
Previously, the reactor had to be driven on a separate thread, which was confusing.
This has a couple notable side effects:
  1. SyncClient is no longer `Clone`.  This is because `reactor::Core`
     is not `Clone`, and creating one is not infallible
     (`Core::new` returns a `Result`).
  2. SyncClient does not use the user-specified `client::Options::handle` or
     `client::Options::remote`, because it constructs its own reactor.
2017-02-01 22:32:25 -08:00

51 lines
1.1 KiB
Rust

// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed except according to those terms.
#![feature(plugin, conservative_impl_trait, test)]
#![plugin(tarpc_plugins)]
#[macro_use]
extern crate tarpc;
#[cfg(test)]
extern crate test;
extern crate env_logger;
extern crate futures;
use futures::Future;
use tarpc::{client, server};
use tarpc::client::sync::Connect;
use tarpc::util::{FirstSocketAddr, Never};
#[cfg(test)]
use test::Bencher;
service! {
rpc ack();
}
#[derive(Clone)]
struct Server;
impl FutureService for Server {
type AckFut = futures::Finished<(), Never>;
fn ack(&self) -> Self::AckFut {
futures::finished(())
}
}
#[cfg(test)]
#[bench]
fn latency(bencher: &mut Bencher) {
let _ = env_logger::init();
let addr = Server.listen("localhost:0".first_socket_addr(),
server::Options::default())
.wait()
.unwrap();
let client = SyncClient::connect(addr, client::Options::default()).unwrap();
bencher.iter(|| {
client.ack().unwrap();
});
}