From 3a3537b129ffceb6e79cee8924b25ab63dfb73e5 Mon Sep 17 00:00:00 2001 From: testisnullus Date: Wed, 11 Sep 2024 13:23:20 +0300 Subject: [PATCH] issue-109, benchmarks were improved --- .gitignore | 2 + brro-compressor/benches/fft_bench.rs | 46 +++++++++++++----- .../tests/wbros/go_gc_heap_goal_bytes.wbro | Bin 0 -> 23668 bytes 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 brro-compressor/tests/wbros/go_gc_heap_goal_bytes.wbro diff --git a/.gitignore b/.gitignore index d54cb23..0ac2ed4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target *.flac .vscode/settings.json + +.idea diff --git a/brro-compressor/benches/fft_bench.rs b/brro-compressor/benches/fft_bench.rs index 0153178..60029f2 100644 --- a/brro-compressor/benches/fft_bench.rs +++ b/brro-compressor/benches/fft_bench.rs @@ -1,9 +1,31 @@ use brro_compressor::compressor::fft::{fft, fft_allowed_error, fft_set, fft_to_data, FFT}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use std::path::PathBuf; +use wavbrro::wavbrro::WavBrro; -// Basic FFT compression benchmark +const TEST_WBRO_PATH: &str = "tests/wbros/go_gc_heap_goal_bytes.wbro"; + +/// Loads the file, and returns the Vec result +fn load_data_from_wbro_file() -> Vec { + let test_file_path = PathBuf::from(TEST_WBRO_PATH); + WavBrro::from_file(&test_file_path).unwrap() +} + +fn pad_to_size(mut data: Vec, desired_size: usize) -> Vec { + // Check if the data length is smaller than the desired size + if data.len() < desired_size { + // Add zeroes to the data until it reaches the desired size + data.resize(desired_size, 1.0); + } else { + // Truncate the data to the exact size if it's larger + data.truncate(desired_size); + } + data +} + +/// Basic FFT compression benchmark fn fft_basic_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); c.bench_function("FFT Compression (Basic)", |b| { b.iter(|| { @@ -15,7 +37,7 @@ fn fft_basic_benchmark(c: &mut Criterion) { // Advanced FFT compression benchmark with custom frequency set fn fft_advanced_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); c.bench_function("FFT Compression (Advanced)", |b| { b.iter(|| { @@ -27,7 +49,7 @@ fn fft_advanced_benchmark(c: &mut Criterion) { // Error-constrained FFT compression benchmark fn fft_error_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); let max_error = 0.01; c.bench_function("FFT Compression (Error Constrained)", |b| { @@ -40,7 +62,7 @@ fn fft_error_benchmark(c: &mut Criterion) { // FFT decompression benchmark fn fft_decompression_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); let compressed_data = fft(&data); c.bench_function("FFT Decompression", |b| { @@ -62,7 +84,7 @@ fn fft_initialization_benchmark(c: &mut Criterion) { // Decompression without FFT benchmark fn decompression_without_fft_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); let compressed_data = fft(&data); c.bench_function("Decompression without FFT", |b| { @@ -75,9 +97,11 @@ fn decompression_without_fft_benchmark(c: &mut Criterion) { // FFT compression benchmark with varying data sizes fn fft_varying_data_size_benchmark(c: &mut Criterion) { - let data_small = vec![1.0; 256]; - let data_medium = vec![1.0; 1024]; - let data_large = vec![1.0; 4096]; + let data = load_data_from_wbro_file(); + + let data_small = pad_to_size(data.clone(), 256); + let data_medium = pad_to_size(data.clone(), 1024); + let data_large = pad_to_size(data, 4096); c.bench_function("FFT Compression (Small Data)", |b| { b.iter(|| { @@ -100,7 +124,7 @@ fn fft_varying_data_size_benchmark(c: &mut Criterion) { // Compression ratio vs. time benchmark fn compression_ratio_vs_time_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); c.bench_function("Compression Ratio vs. Compression Time", |b| { b.iter(|| { @@ -115,7 +139,7 @@ fn compression_ratio_vs_time_benchmark(c: &mut Criterion) { // Multiple compression rounds benchmark fn multiple_compression_rounds_benchmark(c: &mut Criterion) { - let data = vec![1.0; 1024]; + let data = load_data_from_wbro_file(); let rounds = 10; c.bench_function("Multiple Compression Rounds", |b| { diff --git a/brro-compressor/tests/wbros/go_gc_heap_goal_bytes.wbro b/brro-compressor/tests/wbros/go_gc_heap_goal_bytes.wbro new file mode 100644 index 0000000000000000000000000000000000000000..d6741a97e8168118e3d08aab8c95cf62001f0434 GIT binary patch literal 23668 zcmbu{e{c?W9tZGkjfz%zZhEJNV%r{dSKQJILa=CD6U}7>P1>8biyL)RY>-IF>0Uz# zp&P$@Q>>h7a#7tLis{h3sGL@RJTpq-nCn(XiyjtrF&F2#Jnv6(bJLj)dGpU}V)A}I z-(S1Wcc0xSStBzuw8no~jVg-b&vJ4{G^);8o%jC+*7^DIpIOx>w=BTxecvO;3h@6; zx?OwCi~syT9~*_bZj*MwPW*hUn*T|*@p`#$pg*ql4eIG9K1F+)HGY}-hxqR)NjvcS z%|>^AhyTA-)!xU7(4Q9S|7sO-wAm9SPipKOxG3IkR)5Oyh4Fk#HSWkjyMM@F#^G1u zuiLCv^%j0^sc!OEw2#$RV`wLB>6@r;x77RFz8depP3jc5sLL8g_AZInznPJfI)3kF zD%Ldgr=_Z=QtasLvl`}pj6bUtK8pIRUc)}DKi04;5%pQknH!L2HU4o`#*fs}ktpEVraYboA;NTYKH zpgwIwJIRxp%hzK4vMM8+=AYDmFoyYKbsxABZk&uCsoSlc)Mq{TCF;AR(adUT zKdIesI`XX1qCrxhRBt~OdD`>yF#h^2>JM0ldaPE5i^#Kj>AR3;Ri^Yre_8E)4LIId zwXKP0KdZW;6nWZS&q7dL_}yryKIc7L7dLBc ze**P?NIiBM^K&!Ra2tM)H5j=T?PK*5CnC>kJS68`R=wN%a@^mPj@%do&>fXgT zv-&xw@&3vhbeV_xtdWu_$g_q^cOcK|tx3f?VT~M0m-drt|9%g7R`aF($g_HiM7pSQ4vXV2hxVzn2fqy4PLj=y0Yu&U`FpgybeNdoG# zs{UlD&pM$4>Z_#DdI$AcjlFd;{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