Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fa compression 2 #17

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ coverage:
target: 90%
flags:
- fa-compression
patch:
default:
target: 90%
fa-compression:
target: 90%
flags:
- fa-compression

flags:
fa-compression:
Expand Down
4 changes: 4 additions & 0 deletions fa-compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ criterion = "0.5.1"
rand = "0.8.5"

[[bench]]
opt-level = 0
name = "bench_main"
harness = false

[profile.bench]
opt-level=3
31 changes: 31 additions & 0 deletions fa-compression/benches/algorithm1/decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use criterion::black_box;
use fa_compression::algorithm1::{
decode,
encode
};

use super::util::generate_annotation;

/// Generate a random number of encoded annotations.
fn generate_encoded_annotations(count: usize) -> Vec<u8> {
let mut random = rand::thread_rng();

let mut annotations = String::new();
for _ in 0 .. count {
annotations.push_str(&generate_annotation(&mut random));
annotations.push(';');
}
annotations.pop();

encode(annotations.as_str())
}

pub fn decode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("decode_algorithm1", |b| {
b.iter_batched(
|| generate_encoded_annotations(100),
|annotations| black_box(decode(annotations.as_slice())),
criterion::BatchSize::SmallInput
)
});
}
28 changes: 28 additions & 0 deletions fa-compression/benches/algorithm1/encode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use criterion::black_box;
use fa_compression::algorithm1::encode;

use super::util::generate_annotation;

/// Generate a random number of decoded annotations.
fn generate_decoded_annotations(count: usize) -> String {
let mut random = rand::thread_rng();

let mut annotations = String::new();
for _ in 0 .. count {
annotations.push_str(&generate_annotation(&mut random));
annotations.push(';');
}

annotations.pop();
annotations
}

pub fn encode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("encode_algorithm1", |b| {
b.iter_batched(
|| generate_decoded_annotations(100),
|annotations| black_box(encode(annotations.as_str())),
criterion::BatchSize::SmallInput
)
});
}
8 changes: 8 additions & 0 deletions fa-compression/benches/algorithm1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use criterion::criterion_group;

use super::util;

mod decode;
mod encode;

criterion_group!(benches, encode::encode_benchmark, decode::decode_benchmark);
38 changes: 38 additions & 0 deletions fa-compression/benches/algorithm2/decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use criterion::black_box;
use fa_compression::algorithm2::{
decode,
encode,
CompressionTable
};

use super::util::generate_annotation;

fn generate_encoded_annotations_and_table(count: usize) -> (Vec<u8>, CompressionTable) {
let mut random = rand::thread_rng();

let mut compression_table1 = CompressionTable::new();
let mut compression_table2 = CompressionTable::new();

let mut annotations = String::new();
for _ in 0 .. count {
let annotation = generate_annotation(&mut random);
annotations.push_str(&annotation);
annotations.push(';');
compression_table1.add_entry(annotation.clone());
compression_table2.add_entry(annotation);
}

annotations.pop();

(encode(annotations.as_str(), compression_table1), compression_table2)
}

pub fn decode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("decode_algorithm2", |b| {
b.iter_batched(
|| generate_encoded_annotations_and_table(100),
|(annotations, ct)| black_box(decode(annotations.as_slice(), ct)),
criterion::BatchSize::SmallInput
)
});
}
35 changes: 35 additions & 0 deletions fa-compression/benches/algorithm2/encode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use criterion::black_box;
use fa_compression::algorithm2::{
encode,
CompressionTable
};

use super::util::generate_annotation;

fn generate_decoded_annotations_and_table(count: usize) -> (String, CompressionTable) {
let mut random = rand::thread_rng();

let mut compression_table = CompressionTable::new();

let mut annotations = String::new();
for _ in 0 .. count {
let annotation = generate_annotation(&mut random);
annotations.push_str(&annotation);
annotations.push(';');
compression_table.add_entry(annotation);
}

annotations.pop();

(annotations, compression_table)
}

pub fn encode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("encode_algorithm2", |b| {
b.iter_batched(
|| generate_decoded_annotations_and_table(100),
|(annotations, ct)| black_box(encode(annotations.as_str(), ct)),
criterion::BatchSize::SmallInput
)
});
}
8 changes: 8 additions & 0 deletions fa-compression/benches/algorithm2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use criterion::criterion_group;

use super::util;

mod decode;
mod encode;

criterion_group!(benches, encode::encode_benchmark, decode::decode_benchmark);
35 changes: 4 additions & 31 deletions fa-compression/benches/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
use criterion::{
black_box,
criterion_group,
criterion_main
};
use fa_compression::{
decode,
encode
};
use criterion::criterion_main;

mod algorithm1;
mod algorithm2;
mod util;

fn encode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("encode", |b| {
b.iter_batched(
|| util::generate_decoded_annotations(100),
|annotations| black_box(encode(annotations.as_str())),
criterion::BatchSize::SmallInput
)
});
}

fn decode_benchmark(c: &mut criterion::Criterion) {
c.bench_function("decode", |b| {
b.iter_batched(
|| util::generate_encoded_annotations(100),
|annotations| black_box(decode(annotations.as_slice())),
criterion::BatchSize::SmallInput
)
});
}

criterion_group!(benches, encode_benchmark, decode_benchmark);
criterion_main!(benches);
criterion_main!(algorithm1::benches, algorithm2::benches);
28 changes: 0 additions & 28 deletions fa-compression/benches/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fa_compression::encode;
use rand::{
rngs::ThreadRng,
Rng
Expand Down Expand Up @@ -34,30 +33,3 @@ pub fn generate_annotation(random: &mut ThreadRng) -> String {
_ => unreachable!()
}
}

/// Generate a random number of decoded annotations.
pub fn generate_decoded_annotations(count: usize) -> String {
let mut random = rand::thread_rng();

let mut annotations = String::new();
for _ in 0 .. count {
annotations.push_str(&generate_annotation(&mut random));
annotations.push(';');
}
annotations.pop();
annotations
}

/// Generate a random number of encoded annotations.
pub fn generate_encoded_annotations(count: usize) -> Vec<u8> {
let mut random = rand::thread_rng();

let mut annotations = String::new();
for _ in 0 .. count {
annotations.push_str(&generate_annotation(&mut random));
annotations.push(';');
}
annotations.pop();

encode(annotations.as_str())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module provides a function to decode a byte array into a string representation of
//! annotations.

use crate::{
use super::{
CharacterSet,
Decode
};
Expand All @@ -26,7 +26,7 @@ static PREFIXES: [&str; 3] = ["EC:", "GO:", "IPR:IPR"];
/// # Examples
///
/// ```
/// use fa_compression::decode;
/// use fa_compression::algorithm1::decode;
///
/// let input = &[ 44, 44, 44, 189, 17, 26, 56, 173, 18, 116, 117, 225, 67, 116, 110, 17, 153, 39 ];
/// let result = decode(input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module contains the function to encode the input string into a compressed byte vector.

use crate::{
use super::{
CharacterSet,
Encode
};
Expand All @@ -23,7 +23,7 @@ use crate::{
/// # Examples
///
/// ```
/// use fa_compression::encode;
/// use fa_compression::algorithm1::encode;
///
/// let input = "IPR:IPR016364;EC:1.1.1.-;GO:0009279";
/// let encoded = encode(input);
Expand Down
Loading
Loading