Blocks and flowgraph: added this time

This commit is contained in:
2026-03-11 19:31:37 +01:00
parent 13d060776f
commit 6d99d54f4a
9 changed files with 181 additions and 78 deletions

View File

@ -1,73 +1,14 @@
use std::time::Instant;
use oxydsp_flowgraph::edge::{In, Out};
use oxydsp_flowgraph_macros::BlockIO;
use oxydsp_flowgraph::stream;
fn main()
#[derive(BlockIO)]
pub struct Test
{
transfer_test();
return;
let (mut tx, mut rx) = stream::bounded_queue::<usize>(256);
#[input]
input: In<u32>,
std::thread::spawn(move || {
let mut i = 0;
loop
{
let mut writer = tx.write();
while writer.push(i).is_ok()
{
i += 1;
std::thread::yield_now();
}
}
});
loop
{
let mut reader = rx.read();
let len = reader.len();
while let Some(x) = reader.pop()
{
println!("{len}: {x}");
std::thread::yield_now();
}
}
#[output]
output: Out<u32>,
}
fn transfer_test()
{
let (mut tx, mut rx) = stream::bounded_queue::<usize>(256);
let count = 1_000_000_000;
let start = Instant::now();
std::thread::spawn(move || {
let mut i = 0;
while i <= count
{
let mut writer = tx.write();
let mut batch_size = 0;
while i <= count && batch_size < 128 && writer.push(i).is_ok()
{
i += 1;
batch_size += 1;
}
}
});
let mut j = 0;
while j <= count
{
let mut reader = rx.read();
while let Some(x) = reader.pop()
{
assert_eq!(x, j);
j += 1;
}
}
let end = Instant::now();
let time = (end - start).as_secs_f32();
println!(
"Transfer test: {:.2}s, {:.2} MT/s",
time,
count as f32 / (1_000_000. * time)
);
}
fn main() {}