mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Align tool benchmarks with steady-state receive cost
This commit is contained in:
@@ -72,8 +72,73 @@ pub fn run_decode_call(iterations: usize) -> usize {
|
|||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
pub fn run_forward_call_receive(iterations: usize) -> usize {
|
pub fn run_forward_call_receive(iterations: usize) -> usize {
|
||||||
|
let cases = build_forward_call_cases(iterations);
|
||||||
|
run_cases(cases, |(mut root, frame)| {
|
||||||
|
let outcome = root
|
||||||
|
.receive(&Ingress::Local, frame)
|
||||||
|
.expect("forward receive should work");
|
||||||
|
match outcome {
|
||||||
|
EndpointOutcome::Forward { route, frame } => {
|
||||||
|
route_value(route).wrapping_add(frame.len())
|
||||||
|
}
|
||||||
|
EndpointOutcome::Local(_) => 0,
|
||||||
|
EndpointOutcome::Dropped => usize::from(true),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
pub fn run_local_call_receive(iterations: usize) -> usize {
|
||||||
|
let cases = build_local_call_cases(iterations);
|
||||||
|
run_cases(cases, |(mut endpoint, frame)| {
|
||||||
|
let outcome = endpoint
|
||||||
|
.receive(&Ingress::Parent, frame)
|
||||||
|
.expect("local call should work");
|
||||||
|
match outcome {
|
||||||
|
EndpointOutcome::Local(LocalEvent::Call { header, message }) => header
|
||||||
|
.dst_path
|
||||||
|
.len()
|
||||||
|
.wrapping_add(header.src_path.len())
|
||||||
|
.wrapping_add(header.dst_leaf.as_ref().map_or(0, String::len))
|
||||||
|
.wrapping_add(message.data.len())
|
||||||
|
.wrapping_add(message.procedure_id.len()),
|
||||||
|
other => panic!("expected local call event, got {other:?}"),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
pub fn run_hook_data_receive(iterations: usize) -> usize {
|
||||||
|
let cases = build_hook_data_cases(iterations);
|
||||||
|
run_cases(cases, |(mut host, frame)| {
|
||||||
|
let outcome = host
|
||||||
|
.receive(&Ingress::Child(path(&["worker"])), frame)
|
||||||
|
.expect("hook data should work");
|
||||||
|
match outcome {
|
||||||
|
EndpointOutcome::Local(LocalEvent::Data {
|
||||||
|
header, message, ..
|
||||||
|
}) => (header.hook_id.unwrap_or_default() as usize)
|
||||||
|
.wrapping_add(message.data.len())
|
||||||
|
.wrapping_add(message.procedure_id.len())
|
||||||
|
.wrapping_add(message.end_hook as usize),
|
||||||
|
other => panic!("expected local data event, got {other:?}"),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_cases<T>(cases: Vec<T>, mut op: impl FnMut(T) -> usize) -> usize {
|
||||||
let mut checksum = 0usize;
|
let mut checksum = 0usize;
|
||||||
for _ in 0..iterations {
|
for case in cases {
|
||||||
|
checksum = checksum.wrapping_add(op(case));
|
||||||
|
}
|
||||||
|
black_box(checksum)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_forward_call_cases(
|
||||||
|
iterations: usize,
|
||||||
|
) -> Vec<(ProtocolEndpoint, unshell::protocol::FrameBytes)> {
|
||||||
|
(0..iterations)
|
||||||
|
.map(|_| {
|
||||||
let mut root = ProtocolEndpoint::new(
|
let mut root = ProtocolEndpoint::new(
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
None,
|
None,
|
||||||
@@ -90,25 +155,17 @@ pub fn run_forward_call_receive(iterations: usize) -> usize {
|
|||||||
vec![1; 32],
|
vec![1; 32],
|
||||||
)
|
)
|
||||||
.expect("seed call should encode");
|
.expect("seed call should encode");
|
||||||
|
(root, frame)
|
||||||
let outcome = root
|
})
|
||||||
.receive(&Ingress::Local, frame)
|
.collect()
|
||||||
.expect("forward receive should work");
|
|
||||||
let forwarded = match outcome {
|
|
||||||
EndpointOutcome::Forward { route, frame } => route_value(route).wrapping_add(frame.len()),
|
|
||||||
EndpointOutcome::Local(_) => 0,
|
|
||||||
EndpointOutcome::Dropped => usize::from(true),
|
|
||||||
};
|
|
||||||
checksum = checksum.wrapping_add(forwarded);
|
|
||||||
}
|
|
||||||
black_box(checksum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
fn build_local_call_cases(
|
||||||
pub fn run_local_call_receive(iterations: usize) -> usize {
|
iterations: usize,
|
||||||
let mut checksum = 0usize;
|
) -> Vec<(ProtocolEndpoint, unshell::protocol::FrameBytes)> {
|
||||||
for _ in 0..iterations {
|
(0..iterations)
|
||||||
let mut endpoint = ProtocolEndpoint::new(
|
.map(|_| {
|
||||||
|
let endpoint = ProtocolEndpoint::new(
|
||||||
path(&["worker"]),
|
path(&["worker"]),
|
||||||
Some(Vec::new()),
|
Some(Vec::new()),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
@@ -135,29 +192,16 @@ pub fn run_local_call_receive(iterations: usize) -> usize {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.expect("seed local call should encode");
|
.expect("seed local call should encode");
|
||||||
|
(endpoint, frame)
|
||||||
let outcome = endpoint
|
})
|
||||||
.receive(&Ingress::Parent, frame)
|
.collect()
|
||||||
.expect("local call should work");
|
|
||||||
match outcome {
|
|
||||||
EndpointOutcome::Local(LocalEvent::Call { header, message }) => {
|
|
||||||
checksum = checksum
|
|
||||||
.wrapping_add(header.dst_path.len())
|
|
||||||
.wrapping_add(header.src_path.len())
|
|
||||||
.wrapping_add(header.dst_leaf.as_ref().map_or(0, String::len))
|
|
||||||
.wrapping_add(message.data.len())
|
|
||||||
.wrapping_add(message.procedure_id.len());
|
|
||||||
}
|
|
||||||
other => panic!("expected local call event, got {other:?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
black_box(checksum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
fn build_hook_data_cases(
|
||||||
pub fn run_hook_data_receive(iterations: usize) -> usize {
|
iterations: usize,
|
||||||
let mut checksum = 0usize;
|
) -> Vec<(ProtocolEndpoint, unshell::protocol::FrameBytes)> {
|
||||||
for _ in 0..iterations {
|
(0..iterations)
|
||||||
|
.map(|_| {
|
||||||
let mut host = ProtocolEndpoint::new(
|
let mut host = ProtocolEndpoint::new(
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
None,
|
None,
|
||||||
@@ -188,24 +232,9 @@ pub fn run_hook_data_receive(iterations: usize) -> usize {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.expect("seed data should encode");
|
.expect("seed data should encode");
|
||||||
|
(host, frame)
|
||||||
let outcome = host
|
})
|
||||||
.receive(&Ingress::Child(path(&["worker"])), frame)
|
.collect()
|
||||||
.expect("hook data should work");
|
|
||||||
match outcome {
|
|
||||||
EndpointOutcome::Local(LocalEvent::Data {
|
|
||||||
header, message, ..
|
|
||||||
}) => {
|
|
||||||
checksum = checksum
|
|
||||||
.wrapping_add(header.hook_id.unwrap_or_default() as usize)
|
|
||||||
.wrapping_add(message.data.len())
|
|
||||||
.wrapping_add(message.procedure_id.len())
|
|
||||||
.wrapping_add(message.end_hook as usize);
|
|
||||||
}
|
|
||||||
other => panic!("expected local data event, got {other:?}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
black_box(checksum)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn path(parts: &[&str]) -> Vec<String> {
|
pub fn path(parts: &[&str]) -> Vec<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user