Skip to content

Commit

Permalink
Merge pull request #69 from onekey-sec/chisquare
Browse files Browse the repository at this point in the history
Add chi square calculation function to math module.
  • Loading branch information
vlaci authored Nov 6, 2024
2 parents a5400c3 + c4a11cf commit 618b011
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 140 deletions.
157 changes: 155 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ crate-type = [
log = "0.4.22"
pyo3 = "0.22.4"
pyo3-log = "0.11.0"
statrs = "0.17.1"
thiserror = "1.0.64"

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
21 changes: 20 additions & 1 deletion benches/benches_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ fn shannon_entropy(c: &mut Criterion) {
group.finish();
}

criterion_group!(benches, shannon_entropy);
fn chi_square_probability(c: &mut Criterion) {
let mut sample = vec![0u8; 1 * MB];
StdRng::seed_from_u64(5).fill(&mut sample[..]);

let mut group = c.benchmark_group("Chi square probability");

for sample_size in [256, 1 * kB, 64 * kB, 256 * kB, 1 * MB] {
group.throughput(Throughput::Bytes(sample_size as u64));
group.bench_with_input(
BenchmarkId::from_parameter(sample_size),
&sample_size,
|b, &size| {
b.iter(|| unblob_native::math_tools::chi_square_probability(&sample[0..size]));
},
);
}
group.finish();
}

criterion_group!(benches, shannon_entropy, chi_square_probability);

criterion_main!(benches);
Loading

0 comments on commit 618b011

Please sign in to comment.