Skip to content

Commit

Permalink
fix needletail in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Jul 13, 2020
1 parent 58bbaac commit 14c56da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
50 changes: 17 additions & 33 deletions src/core/benches/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate criterion;
use std::fs::File;
use std::io::{Cursor, Read};

use needletail::parse_sequence_reader;
use needletail::parse_fastx_reader;
use sourmash::cmd::ComputeParameters;
use sourmash::signature::Signature;

Expand Down Expand Up @@ -35,59 +35,43 @@ fn add_sequence(c: &mut Criterion) {
b.iter(|| {
let fasta_data = Cursor::new(data_upper.clone());
let mut sig = template_sig.clone();
parse_sequence_reader(
fasta_data,
|_| {},
|rec| {
sig.add_sequence(&rec.seq, false).unwrap();
},
)
.unwrap();
let mut parser = parse_fastx_reader(fasta_data).unwrap();
while let Some(rec) = parser.next() {
sig.add_sequence(&rec.unwrap().seq(), false).unwrap();
}
});
});

group.bench_function("lowercase", |b| {
b.iter(|| {
let fasta_data = Cursor::new(data_lower.clone());
let mut sig = template_sig.clone();
parse_sequence_reader(
fasta_data,
|_| {},
|rec| {
sig.add_sequence(&rec.seq, false).unwrap();
},
)
.unwrap();
let mut parser = parse_fastx_reader(fasta_data).unwrap();
while let Some(rec) = parser.next() {
sig.add_sequence(&rec.unwrap().seq(), false).unwrap();
}
});
});

group.bench_function("invalid kmers", |b| {
b.iter(|| {
let fasta_data = Cursor::new(data_errors.clone());
let mut sig = template_sig.clone();
parse_sequence_reader(
fasta_data,
|_| {},
|rec| {
sig.add_sequence(&rec.seq, true).unwrap();
},
)
.unwrap();
let mut parser = parse_fastx_reader(fasta_data).unwrap();
while let Some(rec) = parser.next() {
sig.add_sequence(&rec.unwrap().seq(), true).unwrap();
}
});
});

group.bench_function("force with valid kmers", |b| {
b.iter(|| {
let fasta_data = Cursor::new(data_upper.clone());
let mut sig = template_sig.clone();
parse_sequence_reader(
fasta_data,
|_| {},
|rec| {
sig.add_sequence(&rec.seq, true).unwrap();
},
)
.unwrap();
let mut parser = parse_fastx_reader(fasta_data).unwrap();
while let Some(rec) = parser.next() {
sig.add_sequence(&rec.unwrap().seq(), true).unwrap();
}
});
});
}
Expand Down
14 changes: 12 additions & 2 deletions src/core/src/sketch/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ impl KmerMinHash {
first.count_common(&downsampled_mh, false)
} else {
self.check_compatible(other)?;
let iter = Intersection::new(self.mins.iter(), other.mins.iter());
let iter = if self.size() < other.size() {
Intersection::new(self.mins.iter(), other.mins.iter())
} else {
Intersection::new(other.mins.iter(), self.mins.iter())
};

Ok(iter.count() as u64)
}
Expand Down Expand Up @@ -669,6 +673,8 @@ impl KmerMinHash {
unimplemented!() // @CTB fixme
}

// TODO: check which one is smaller, swap around if needed

let abunds = self.abunds.as_ref().unwrap();
let other_abunds = other.abunds.as_ref().unwrap();

Expand Down Expand Up @@ -1698,7 +1704,11 @@ impl KmerMinHashBTree {
first.count_common(&downsampled_mh, false)
} else {
self.check_compatible(other)?;
let iter = Intersection::new(self.mins.iter(), other.mins.iter());
let iter = if self.size() < other.size() {
Intersection::new(self.mins.iter(), other.mins.iter())
} else {
Intersection::new(other.mins.iter(), self.mins.iter())
};

Ok(iter.count() as u64)
}
Expand Down

0 comments on commit 14c56da

Please sign in to comment.