Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
Signed-off-by: wcampbell <[email protected]>
  • Loading branch information
wcampbell0x2a committed Nov 2, 2021
1 parent 4598d0c commit 0beb60d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ hex = "0.4"

[dev-dependencies]
assert_hex = "0.2"
criterion = "0.3"

[[bench]]
name = "demod_benchmark"
harness = false
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
Fork of https://github.com/johnwstanford/dump1090_rs, without parsing messages.
This project is meant to just forward bytes from the the demodulated iq stream from a rtlsdr to my own [adsb_deku](https://github.com/wcampbell0x2a/adsb_deku) library/apps.

# Usage
## Usage

```
cargo r --release
```

# Testing
## Testing
```
cargo t --release
```

## Benchmark

Reading from a 256KB iq sample to ADS-B bytes takes ~3.5218 ms, but feel free to run benchmarks on your computer.
```
cargo bench
```

# Changes
See [CHANGELOG.md](https://github.com/wcampbell0x2a/dump1090_rs/blob/master/CHANGELOG.md)
29 changes: 29 additions & 0 deletions benches/demod_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use byteorder::{BigEndian, ReadBytesExt};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::io::Cursor;

fn demod_iq(iq_buf: &[u8]) -> Vec<[u8; 14]> {
let mut modes = dump1090_rs::Modes::default();
let outbuf = &mut modes.next_buffer(2_400_000);

let mut rdr = Cursor::new(&iq_buf);

while let Ok(iq) = rdr.read_u16::<BigEndian>() {
let this_mag: u16 = dump1090_rs::MAG_LUT[iq as usize];

outbuf.push(this_mag);
}
dump1090_rs::demod_2400::demodulate2400(outbuf).unwrap()
}

fn criterion_benchmark(c: &mut Criterion) {
let f_buffer_00 = std::fs::read("tests/test_00.iq").unwrap();
let f_buffer_01 = std::fs::read("tests/test_01.iq").unwrap();
let f_buffer_02 = std::fs::read("tests/test_02.iq").unwrap();
c.bench_function("00", |b| b.iter(|| demod_iq(&f_buffer_00)));
c.bench_function("01", |b| b.iter(|| demod_iq(&f_buffer_01)));
c.bench_function("02", |b| b.iter(|| demod_iq(&f_buffer_02)));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
8 changes: 8 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ fn demod_iq(iq_buf: &[u8]) -> Vec<[u8; 14]> {
dump1090_rs::demod_2400::demodulate2400(outbuf).unwrap()
}

#[test]
fn test_00() {
let f_buffer = std::fs::read("tests/test_00.iq").unwrap();
let resulting_data = demod_iq(&f_buffer);
let expected_data = [[0x5d, 0xa0, 0x56, 0xf9, 0x89, 0xc2, 0x29, 0x85, 0x29, 0x31, 0x3a, 0xc3, 0x53, 0x10]];
assert_eq_hex!(expected_data, &*resulting_data);
}

#[test]
fn test_01() {
let f_buffer = std::fs::read("tests/test_01.iq").unwrap();
Expand Down
Loading

0 comments on commit 0beb60d

Please sign in to comment.