Created
August 23, 2022 12:02
-
-
Save bastibl/a1e68085bc0524265291e58aea23b368 to your computer and use it in GitHub Desktop.
FutureSDR Mocked Apply Block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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