Skip to content

Commit

Permalink
Add FASTA benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
peri4n committed Oct 1, 2024
1 parent 38dde15 commit 303efdc
Show file tree
Hide file tree
Showing 9 changed files with 38,883 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ path = "src/lib.rs"
criterion = "0.5.1"

[[bench]]
name = "sequence_benchmark"
name = "all_benchmark"
harness = false
8 changes: 8 additions & 0 deletions benches/all_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use criterion::criterion_main;

mod benchmarks;

criterion_main! {
benchmarks::fasta_benchmark::fasta_benches,
benchmarks::dna_benchmark::dna_benches,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, Criterion};
use nuc::dna::Dna;

pub fn counting_nucleotides_benchmark(c: &mut Criterion) {
Expand All @@ -11,5 +11,4 @@ pub fn reverse_complement_benchmark(c: &mut Criterion) {
c.bench_function("create the reverse complement", |b| b.iter(|| dna.rc()));
}

criterion_group!(benches, counting_nucleotides_benchmark, reverse_complement_benchmark);
criterion_main!(benches);
criterion_group!(dna_benches, counting_nucleotides_benchmark, reverse_complement_benchmark);
15 changes: 15 additions & 0 deletions benches/benchmarks/fasta_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::fs::File;

use criterion::{criterion_group, Criterion};
use nuc::fasta::FastaReader;

pub fn parsing_chromosome1_benchmark(c: &mut Criterion) {
c.bench_function("parsing a random 3MB FASTA file", |b| {
b.iter(|| {
let reader = FastaReader::new(File::open("benches/random.fa").unwrap());
assert_eq!(reader.into_iter().count(), 13);
})
});
}

criterion_group!(fasta_benches, parsing_chromosome1_benchmark);
2 changes: 2 additions & 0 deletions benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod fasta_benchmark;
pub mod dna_benchmark;
38,855 changes: 38,855 additions & 0 deletions benches/random.fa

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/dna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl Dna {
dna.nucleotides[i] = hash_chars_be(b);
i += 1;
}
dbg!(&dna);

dna
}
Expand Down
1 change: 0 additions & 1 deletion src/fasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ impl<R: Read + std::fmt::Debug> Iterator for FastaReader<R> {
type Item = FastaDna;

fn next(&mut self) -> Option<Self::Item> {
println!("next:");
let mut id = self.next_id.take().unwrap_or_default();
let mut sequence = String::with_capacity(1000);

Expand Down
7 changes: 0 additions & 7 deletions tests/fasta_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,3 @@ fn can_read_an_empty_fasta_file() {
let records = FastaReader::new("".as_bytes()).into_iter().collect::<Vec<_>>();
assert_eq!(records, vec![]);
}

#[test]
fn read_chromosome1() {
let reader = FastaReader::new(File::open("/home/fbull/test.fa").unwrap());

assert_eq!(reader.into_iter().count(), 1);
}

0 comments on commit 303efdc

Please sign in to comment.