Skip to content

Commit

Permalink
perf: tune translate_cds implementation (#80) (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Apr 3, 2023
1 parent 5f3c4cd commit a608ba1
Show file tree
Hide file tree
Showing 6 changed files with 626 additions and 447 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.fasta filter=lfs diff=lfs merge=lfs -text
tests/data/*.gz filter=lfs diff=lfs merge=lfs -text
tests/data/*/*.gz filter=lfs diff=lfs merge=lfs -text
tests/data/*.fasta filter=lfs diff=lfs merge=lfs -text
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
perf.*

/target
/Cargo.lock

Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ linked-hash-map = { version = "0.5.6", features = ["serde", "serde_impl"] }
log = "0.4.17"
md-5 = "0.10.5"
nom = "7.1.3"
phf = { version = "0.11.1", features = ["macros"] }
postgres = { version = "0.19.4", features = ["with-chrono-0_4"] }
quick_cache = "0.2.2"
regex = "1.7.1"
rustc-hash = "1.1.0"
seqrepo = { version = "0.3.0" }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
Expand All @@ -38,3 +38,8 @@ env_logger = "0.10.0"
pretty_assertions = "1.3.0"
rstest = "0.17.0"
test-log = "0.2.11"
criterion = "0.3"

[[bench]]
name = "translate_cds"
harness = false
3 changes: 3 additions & 0 deletions benches/TTN.fasta
Git LFS file not shown
27 changes: 27 additions & 0 deletions benches/translate_cds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use criterion::{criterion_group, criterion_main, Criterion};
use hgvs::sequences::{translate_cds, TranslationTable};

/// TTN FASTA string from https://www.ncbi.nlm.nih.gov/nuccore/NM_001126114.1
static TTN_FASTA: &str = include_str!("TTN.fasta");

lazy_static::lazy_static! {
/// Raw TTN sequence.
static ref SEQ_TTN: String = {
let mut seq = String::new();
for line in TTN_FASTA.lines() {
if !line.starts_with('>') {
seq.push_str(line);
}
}
seq
};
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("translate_cds TTN", |b| {
b.iter(|| translate_cds(&SEQ_TTN, true, "*", TranslationTable::Standard).unwrap())
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading

0 comments on commit a608ba1

Please sign in to comment.