This commit is contained in:
2026-03-11 13:33:21 +01:00
parent 5cfc944703
commit d0773783dc
5 changed files with 625 additions and 1 deletions

View File

@ -1,4 +1,73 @@
use std::time::Instant;
use oxydsp_flowgraph::stream;
fn main()
{
println!("Hello, world!");
transfer_test();
return;
let (mut tx, mut rx) = stream::bounded_queue::<usize>(256);
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();
}
}
}
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)
);
}