Skip to content
Snippets Groups Projects
Commit 174cca1c authored by Martin Larralde's avatar Martin Larralde
Browse files

Add benchmarks for the different `Threshold` implementations

parent b0ac0a6c
No related branches found
No related tags found
No related merge requests found
File moved
#![feature(test)]
extern crate lightmotif;
extern crate test;
use lightmotif::abc::Dna;
use lightmotif::num::StrictlyPositive;
use lightmotif::num::U16;
use lightmotif::num::U32;
use lightmotif::pli::Pipeline;
use lightmotif::pli::Score;
use lightmotif::pli::StripedScores;
use lightmotif::pli::Threshold;
use lightmotif::pwm::CountMatrix;
use lightmotif::seq::EncodedSequence;
use lightmotif::seq::StripedSequence;
const SEQUENCE: &str = include_str!("ecoli.txt");
fn bench<C: StrictlyPositive, P: Score<Dna, C> + Threshold<C>>(
bencher: &mut test::Bencher,
pli: &P,
) {
let mut striped = StripedSequence::<Dna, C>::encode(SEQUENCE).unwrap();
let cm = CountMatrix::<Dna>::from_sequences(&[
EncodedSequence::encode("GTTGACCTTATCAAC").unwrap(),
EncodedSequence::encode("GTTGATCCAGTCAAC").unwrap(),
])
.unwrap();
let pbm = cm.to_freq(0.1);
let pssm = pbm.to_scoring(None);
striped.configure(&pssm);
let mut scores = StripedScores::empty();
pli.score_into(&striped, &pssm, &mut scores);
bencher.bytes = (std::mem::size_of::<f32>() * scores.len()) as u64;
bencher.iter(|| {
test::black_box(pli.threshold(&scores, 0.0));
});
}
#[bench]
fn bench_generic(bencher: &mut test::Bencher) {
let pli = Pipeline::generic();
bench::<U32, _>(bencher, &pli);
}
#[cfg(target_feature = "sse2")]
#[bench]
fn bench_sse2(bencher: &mut test::Bencher) {
let pli = Pipeline::sse2().unwrap();
bench::<U16, _>(bencher, &pli);
}
#[cfg(target_feature = "sse2")]
#[bench]
fn bench_sse2_32(bencher: &mut test::Bencher) {
let pli = Pipeline::sse2().unwrap();
bench::<U32, _>(bencher, &pli);
}
#[cfg(target_feature = "avx2")]
#[bench]
fn bench_avx2(bencher: &mut test::Bencher) {
let pli = Pipeline::avx2().unwrap();
bench(bencher, &pli);
}
......@@ -8,7 +8,6 @@ use std::ops::Div;
use std::ops::Rem;
use typenum::consts::U16;
use typenum::consts::U4;
use typenum::marker_traits::Unsigned;
use typenum::marker_traits::Zero;
......@@ -234,7 +233,7 @@ where
((offset + 12) * data.rows()) as i32,
);
// Process rows iteratively
for (i, row) in data.iter().enumerate() {
for row in data.iter() {
// load scores for the current row
let r1 = _mm_load_ps(row[offset + 0x00..].as_ptr());
let r2 = _mm_load_ps(row[offset + 0x04..].as_ptr());
......
......@@ -95,6 +95,10 @@ fn test_threshold<C: StrictlyPositive, P: Score<Dna, C> + Threshold<C>>(pli: &P)
let mut positions = pli.threshold(&result, -10.0);
positions.sort_unstable();
assert_eq!(positions, vec![18, 27, 32]);
let mut positions = pli.threshold(&result, -15.0);
positions.sort_unstable();
assert_eq!(positions, vec![10, 13, 14, 18, 24, 27, 32, 35, 40, 47]);
}
#[test]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment