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)]
|
||||
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;
|
||||
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(
|
||||
Vec::new(),
|
||||
None,
|
||||
@@ -90,25 +155,17 @@ pub fn run_forward_call_receive(iterations: usize) -> usize {
|
||||
vec![1; 32],
|
||||
)
|
||||
.expect("seed call should encode");
|
||||
|
||||
let outcome = root
|
||||
.receive(&Ingress::Local, frame)
|
||||
.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)
|
||||
(root, frame)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn run_local_call_receive(iterations: usize) -> usize {
|
||||
let mut checksum = 0usize;
|
||||
for _ in 0..iterations {
|
||||
let mut endpoint = ProtocolEndpoint::new(
|
||||
fn build_local_call_cases(
|
||||
iterations: usize,
|
||||
) -> Vec<(ProtocolEndpoint, unshell::protocol::FrameBytes)> {
|
||||
(0..iterations)
|
||||
.map(|_| {
|
||||
let endpoint = ProtocolEndpoint::new(
|
||||
path(&["worker"]),
|
||||
Some(Vec::new()),
|
||||
Vec::new(),
|
||||
@@ -135,29 +192,16 @@ pub fn run_local_call_receive(iterations: usize) -> usize {
|
||||
},
|
||||
)
|
||||
.expect("seed local call should encode");
|
||||
|
||||
let outcome = endpoint
|
||||
.receive(&Ingress::Parent, frame)
|
||||
.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)
|
||||
(endpoint, frame)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn run_hook_data_receive(iterations: usize) -> usize {
|
||||
let mut checksum = 0usize;
|
||||
for _ in 0..iterations {
|
||||
fn build_hook_data_cases(
|
||||
iterations: usize,
|
||||
) -> Vec<(ProtocolEndpoint, unshell::protocol::FrameBytes)> {
|
||||
(0..iterations)
|
||||
.map(|_| {
|
||||
let mut host = ProtocolEndpoint::new(
|
||||
Vec::new(),
|
||||
None,
|
||||
@@ -188,24 +232,9 @@ pub fn run_hook_data_receive(iterations: usize) -> usize {
|
||||
},
|
||||
)
|
||||
.expect("seed data should encode");
|
||||
|
||||
let outcome = host
|
||||
.receive(&Ingress::Child(path(&["worker"])), frame)
|
||||
.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)
|
||||
(host, frame)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn path(parts: &[&str]) -> Vec<String> {
|
||||
|
||||
Reference in New Issue
Block a user