Skip to content

Instantly share code, notes, and snippets.

@bastibl
Created August 23, 2022 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastibl/a1e68085bc0524265291e58aea23b368 to your computer and use it in GitHub Desktop.
Save bastibl/a1e68085bc0524265291e58aea23b368 to your computer and use it in GitHub Desktop.
FutureSDR Mocked Apply Block
use futuresdr::blocks::Apply;
use futuresdr::runtime::Mocker;
use rand::Rng;
use std::time;
const NUM_SAMPLES: usize = 100_000_000;
fn main() {
let input: Vec<u8> = rand::thread_rng()
.sample_iter(rand::distributions::Uniform::<u8>::new(0, 127))
.take(NUM_SAMPLES)
.collect();
let block = Apply::new(|x: &u8| x.wrapping_add(1));
let mut mocker = Mocker::new(block);
mocker.input(0, input.clone());
mocker.init_output::<u8>(0, NUM_SAMPLES);
let now = time::Instant::now();
mocker.run();
let elapsed = now.elapsed();
println!("took: {:?}", elapsed);
let output = mocker.output::<u8>(0);
assert_eq!(input.len(), output.len());
for (a, b) in input.iter().zip(output.iter()) {
assert_eq!(a.wrapping_add(1), *b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment