mirror of https://github.com/dswd/vpncloud.git
Fix benches
This commit is contained in:
parent
1101fe65e0
commit
68f4cb7787
|
@ -1,27 +1,30 @@
|
||||||
#![allow(dead_code, unused_macros, unused_imports)]
|
#![allow(dead_code, unused_macros, unused_imports)]
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use]
|
||||||
#[macro_use] extern crate log;
|
extern crate serde;
|
||||||
#[macro_use] extern crate tokio;
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tokio;
|
||||||
|
|
||||||
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
|
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
|
||||||
|
|
||||||
use smallvec::smallvec;
|
|
||||||
use ring::aead;
|
use ring::aead;
|
||||||
|
use smallvec::smallvec;
|
||||||
|
|
||||||
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, UdpSocket};
|
|
||||||
|
|
||||||
include!(".code.rs");
|
include!(".code.rs");
|
||||||
|
|
||||||
pub use error::Error;
|
|
||||||
use util::{MockTimeSource, MsgBuffer};
|
|
||||||
use types::{Address, Range};
|
|
||||||
use table::{ClaimTable};
|
|
||||||
use device::Type;
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use payload::{Packet, Frame, Protocol};
|
|
||||||
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
||||||
use tests::common::{TunSimulator, TapSimulator};
|
use device::Type;
|
||||||
|
pub use error::Error;
|
||||||
|
use payload::{Frame, Packet, Protocol};
|
||||||
|
use table::ClaimTable;
|
||||||
|
use tests::common::{TapSimulator, TunSimulator};
|
||||||
|
use types::{Address, Range};
|
||||||
|
use util::{MockTimeSource, MsgBuffer};
|
||||||
|
|
||||||
fn udp_send(c: &mut Criterion) {
|
fn udp_send(c: &mut Criterion) {
|
||||||
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
@ -48,7 +51,7 @@ fn decode_ipv4(c: &mut Criterion) {
|
||||||
fn decode_ipv6(c: &mut Criterion) {
|
fn decode_ipv6(c: &mut Criterion) {
|
||||||
let data = [
|
let data = [
|
||||||
0x60, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5,
|
0x60, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5,
|
||||||
4, 3, 2, 1
|
4, 3, 2, 1,
|
||||||
];
|
];
|
||||||
let mut g = c.benchmark_group("payload");
|
let mut g = c.benchmark_group("payload");
|
||||||
g.throughput(Throughput::Bytes(1400));
|
g.throughput(Throughput::Bytes(1400));
|
||||||
|
@ -108,7 +111,7 @@ fn lookup_cold(c: &mut Criterion) {
|
||||||
fn crypto_bench(c: &mut Criterion, algo: &'static aead::Algorithm) {
|
fn crypto_bench(c: &mut Criterion, algo: &'static aead::Algorithm) {
|
||||||
let mut buffer = MsgBuffer::new(EXTRA_LEN);
|
let mut buffer = MsgBuffer::new(EXTRA_LEN);
|
||||||
buffer.set_length(1400);
|
buffer.set_length(1400);
|
||||||
let (mut sender, mut receiver) = create_dummy_pair(algo);
|
let (sender, receiver) = create_dummy_pair(algo);
|
||||||
let mut g = c.benchmark_group("crypto");
|
let mut g = c.benchmark_group("crypto");
|
||||||
g.throughput(Throughput::Bytes(2 * 1400));
|
g.throughput(Throughput::Bytes(2 * 1400));
|
||||||
g.bench_function(format!("{:?}", algo), |b| {
|
g.bench_function(format!("{:?}", algo), |b| {
|
||||||
|
@ -133,6 +136,7 @@ fn crypto_aes256(c: &mut Criterion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn full_communication_tun_router(c: &mut Criterion) {
|
fn full_communication_tun_router(c: &mut Criterion) {
|
||||||
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Error);
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
let config1 = Config {
|
let config1 = Config {
|
||||||
device_type: Type::Tun,
|
device_type: Type::Tun,
|
||||||
|
@ -147,59 +151,78 @@ fn full_communication_tun_router(c: &mut Criterion) {
|
||||||
..Config::default()
|
..Config::default()
|
||||||
};
|
};
|
||||||
let mut sim = TunSimulator::new();
|
let mut sim = TunSimulator::new();
|
||||||
let node1 = sim.add_node(false, &config1);
|
|
||||||
let node2 = sim.add_node(false, &config2);
|
|
||||||
|
|
||||||
sim.connect(node1, node2);
|
let (node1, node2) = runtime.block_on(async {
|
||||||
sim.simulate_all_messages();
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let node1 = sim.add_node(false, &config1).await;
|
||||||
|
let node2 = sim.add_node(false, &config2).await;
|
||||||
|
|
||||||
|
sim.connect(node1, node2).await;
|
||||||
|
sim.simulate_all_messages().await;
|
||||||
assert!(sim.is_connected(node1, node2));
|
assert!(sim.is_connected(node1, node2));
|
||||||
assert!(sim.is_connected(node2, node1));
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
(node1, node2)
|
||||||
|
});
|
||||||
|
|
||||||
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
||||||
payload.append(&mut vec![0; 1400]);
|
payload.append(&mut vec![0; 1400]);
|
||||||
let mut g = c.benchmark_group("full_communication");
|
let mut g = c.benchmark_group("full_communication");
|
||||||
g.throughput(Throughput::Bytes(2 * 1400));
|
g.throughput(Throughput::Bytes(2 * 1400));
|
||||||
g.bench_function("tun_router", |b| {
|
g.bench_function("tun_router", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| runtime.block_on(async {
|
||||||
sim.put_payload(node1, payload.clone());
|
sim.put_payload(node1, payload.clone()).await;
|
||||||
sim.simulate_all_messages();
|
sim.simulate_all_messages().await;
|
||||||
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
g.finish()
|
g.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn full_communication_tap_switch(c: &mut Criterion) {
|
fn full_communication_tap_switch(c: &mut Criterion) {
|
||||||
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Error);
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
let config = Config { device_type: Type::Tap, ..Config::default() };
|
let config = Config { device_type: Type::Tap, ..Config::default() };
|
||||||
let mut sim = TapSimulator::new();
|
let mut sim = TapSimulator::new();
|
||||||
let node1 = sim.add_node(false, &config);
|
|
||||||
let node2 = sim.add_node(false, &config);
|
|
||||||
|
|
||||||
sim.connect(node1, node2);
|
let (node1, node2) = runtime.block_on(async {
|
||||||
sim.simulate_all_messages();
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let node1 = sim.add_node(false, &config).await;
|
||||||
|
let node2 = sim.add_node(false, &config).await;
|
||||||
|
|
||||||
|
sim.connect(node1, node2).await;
|
||||||
|
sim.simulate_all_messages().await;
|
||||||
assert!(sim.is_connected(node1, node2));
|
assert!(sim.is_connected(node1, node2));
|
||||||
assert!(sim.is_connected(node2, node1));
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
(node1, node2)
|
||||||
|
});
|
||||||
|
|
||||||
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
||||||
payload.append(&mut vec![0; 1400]);
|
payload.append(&mut vec![0; 1400]);
|
||||||
let mut g = c.benchmark_group("full_communication");
|
let mut g = c.benchmark_group("full_communication");
|
||||||
g.throughput(Throughput::Bytes(2 * 1400));
|
g.throughput(Throughput::Bytes(2 * 1400));
|
||||||
g.bench_function("tap_switch", |b| {
|
g.bench_function("tap_switch", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| runtime.block_on(async {
|
||||||
sim.put_payload(node1, payload.clone());
|
sim.put_payload(node1, payload.clone()).await;
|
||||||
sim.simulate_all_messages();
|
sim.simulate_all_messages().await;
|
||||||
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
g.finish()
|
g.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches,
|
criterion_group!(
|
||||||
|
benches,
|
||||||
udp_send,
|
udp_send,
|
||||||
decode_ipv4, decode_ipv6, decode_ethernet, decode_ethernet_with_vlan,
|
decode_ipv4,
|
||||||
lookup_cold, lookup_warm,
|
decode_ipv6,
|
||||||
crypto_chacha20, crypto_aes128, crypto_aes256,
|
decode_ethernet,
|
||||||
full_communication_tun_router, full_communication_tap_switch
|
decode_ethernet_with_vlan,
|
||||||
|
lookup_cold,
|
||||||
|
lookup_warm,
|
||||||
|
crypto_chacha20,
|
||||||
|
crypto_aes128,
|
||||||
|
crypto_aes256,
|
||||||
|
full_communication_tun_router,
|
||||||
|
full_communication_tap_switch
|
||||||
);
|
);
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
|
@ -1,27 +1,30 @@
|
||||||
#![allow(dead_code, unused_macros, unused_imports)]
|
#![allow(dead_code, unused_macros, unused_imports)]
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use]
|
||||||
#[macro_use] extern crate log;
|
extern crate serde;
|
||||||
#[macro_use] extern crate tokio;
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate tokio;
|
||||||
|
|
||||||
use iai::{black_box, main};
|
use iai::{black_box, main};
|
||||||
|
|
||||||
use smallvec::smallvec;
|
|
||||||
use ring::aead;
|
use ring::aead;
|
||||||
|
use smallvec::smallvec;
|
||||||
|
|
||||||
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, UdpSocket};
|
|
||||||
|
|
||||||
include!(".code.rs");
|
include!(".code.rs");
|
||||||
|
|
||||||
pub use error::Error;
|
|
||||||
use util::{MockTimeSource, MsgBuffer};
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use types::{Address, Range};
|
|
||||||
use device::Type;
|
|
||||||
use table::{ClaimTable};
|
|
||||||
use payload::{Packet, Frame, Protocol};
|
|
||||||
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
||||||
use tests::common::{TunSimulator, TapSimulator};
|
use device::Type;
|
||||||
|
pub use error::Error;
|
||||||
|
use payload::{Frame, Packet, Protocol};
|
||||||
|
use table::ClaimTable;
|
||||||
|
use tests::common::{TapSimulator, TunSimulator};
|
||||||
|
use types::{Address, Range};
|
||||||
|
use util::{MockTimeSource, MsgBuffer};
|
||||||
|
|
||||||
fn udp_send() {
|
fn udp_send() {
|
||||||
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
@ -38,7 +41,7 @@ fn decode_ipv4() {
|
||||||
fn decode_ipv6() {
|
fn decode_ipv6() {
|
||||||
let data = [
|
let data = [
|
||||||
0x60, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5,
|
0x60, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5,
|
||||||
4, 3, 2, 1
|
4, 3, 2, 1,
|
||||||
];
|
];
|
||||||
Packet::parse(&black_box(data)).unwrap();
|
Packet::parse(&black_box(data)).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -75,7 +78,7 @@ fn lookup_cold() {
|
||||||
fn crypto_bench(algo: &'static aead::Algorithm) {
|
fn crypto_bench(algo: &'static aead::Algorithm) {
|
||||||
let mut buffer = MsgBuffer::new(EXTRA_LEN);
|
let mut buffer = MsgBuffer::new(EXTRA_LEN);
|
||||||
buffer.set_length(1400);
|
buffer.set_length(1400);
|
||||||
let (mut sender, mut receiver) = create_dummy_pair(algo);
|
let (sender, receiver) = create_dummy_pair(algo);
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
sender.encrypt(black_box(&mut buffer));
|
sender.encrypt(black_box(&mut buffer));
|
||||||
receiver.decrypt(&mut buffer).unwrap();
|
receiver.decrypt(&mut buffer).unwrap();
|
||||||
|
@ -95,6 +98,7 @@ fn crypto_aes256() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn full_communication_tun_router() {
|
fn full_communication_tun_router() {
|
||||||
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Error);
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
let config1 = Config {
|
let config1 = Config {
|
||||||
device_type: Type::Tun,
|
device_type: Type::Tun,
|
||||||
|
@ -109,48 +113,69 @@ fn full_communication_tun_router() {
|
||||||
..Config::default()
|
..Config::default()
|
||||||
};
|
};
|
||||||
let mut sim = TunSimulator::new();
|
let mut sim = TunSimulator::new();
|
||||||
let node1 = sim.add_node(false, &config1);
|
let (node1, node2) = runtime.block_on(async {
|
||||||
let node2 = sim.add_node(false, &config2);
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let node1 = sim.add_node(false, &config1).await;
|
||||||
|
let node2 = sim.add_node(false, &config2).await;
|
||||||
|
|
||||||
sim.connect(node1, node2);
|
sim.connect(node1, node2).await;
|
||||||
sim.simulate_all_messages();
|
sim.simulate_all_messages().await;
|
||||||
assert!(sim.is_connected(node1, node2));
|
assert!(sim.is_connected(node1, node2));
|
||||||
assert!(sim.is_connected(node2, node1));
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
(node1, node2)
|
||||||
|
});
|
||||||
|
|
||||||
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
||||||
payload.append(&mut vec![0; 1400]);
|
payload.append(&mut vec![0; 1400]);
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
sim.put_payload(node1, payload.clone());
|
runtime.block_on(async {
|
||||||
sim.simulate_all_messages();
|
sim.put_payload(node1, payload.clone()).await;
|
||||||
|
sim.simulate_all_messages().await;
|
||||||
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn full_communication_tap_switch() {
|
fn full_communication_tap_switch() {
|
||||||
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Error);
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
let config = Config { device_type: Type::Tap, ..Config::default() };
|
let config = Config { device_type: Type::Tap, ..Config::default() };
|
||||||
let mut sim = TapSimulator::new();
|
let mut sim = TapSimulator::new();
|
||||||
let node1 = sim.add_node(false, &config);
|
|
||||||
let node2 = sim.add_node(false, &config);
|
|
||||||
|
|
||||||
sim.connect(node1, node2);
|
let (node1, node2) = runtime.block_on(async {
|
||||||
sim.simulate_all_messages();
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let node1 = sim.add_node(false, &config).await;
|
||||||
|
let node2 = sim.add_node(false, &config).await;
|
||||||
|
|
||||||
|
sim.connect(node1, node2).await;
|
||||||
|
sim.simulate_all_messages().await;
|
||||||
assert!(sim.is_connected(node1, node2));
|
assert!(sim.is_connected(node1, node2));
|
||||||
assert!(sim.is_connected(node2, node1));
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
(node1, node2)
|
||||||
|
});
|
||||||
|
|
||||||
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
||||||
payload.append(&mut vec![0; 1400]);
|
payload.append(&mut vec![0; 1400]);
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
sim.put_payload(node1, payload.clone());
|
runtime.block_on(async {
|
||||||
sim.simulate_all_messages();
|
sim.put_payload(node1, payload.clone()).await;
|
||||||
|
sim.simulate_all_messages().await;
|
||||||
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iai::main!(
|
iai::main!(
|
||||||
udp_send,
|
udp_send,
|
||||||
decode_ipv4, decode_ipv6, decode_ethernet, decode_ethernet_with_vlan,
|
decode_ipv4,
|
||||||
lookup_cold, lookup_warm,
|
decode_ipv6,
|
||||||
crypto_chacha20, crypto_aes128, crypto_aes256,
|
decode_ethernet,
|
||||||
full_communication_tun_router, full_communication_tap_switch
|
decode_ethernet_with_vlan,
|
||||||
|
lookup_cold,
|
||||||
|
lookup_warm,
|
||||||
|
crypto_chacha20,
|
||||||
|
crypto_aes128,
|
||||||
|
crypto_aes256,
|
||||||
|
full_communication_tun_router,
|
||||||
|
full_communication_tap_switch
|
||||||
);
|
);
|
Loading…
Reference in New Issue