Skip to content

Commit c1f870e

Browse files
committed
Compress 11 MiB Sherlock text file
1 parent 29a2ed2 commit c1f870e

File tree

8 files changed

+97
-247996
lines changed

8 files changed

+97
-247996
lines changed

collector/runtime-benchmarks/compression/Cargo.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/runtime-benchmarks/compression/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
benchlib = { path = "../../benchlib" }
9+
benchlib = { path = "../../benchlib", features = ["compression"] }
1010
brotli = "3.3.4"
1111

1212
[workspace]

collector/runtime-benchmarks/compression/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::io::Write;
33
use brotli::enc::BrotliEncoderParams;
44

55
use benchlib::benchmark::run_benchmark_group;
6+
use benchlib::decompress_file;
67

7-
const TEXT_SHERLOCK: &str = include_str!("../../data/sherlock.txt");
8+
const TEXT_SHERLOCK: &[u8] = include_bytes!("../../data/sherlock.txt.gz");
89

910
fn compress(data: &str) -> Vec<u8> {
1011
let mut target: Vec<u8> = Vec::with_capacity(1024 * 1024);
@@ -18,19 +19,22 @@ fn compress(data: &str) -> Vec<u8> {
1819
}
1920

2021
fn main() {
22+
let sherlock_text = String::from_utf8(decompress_file(TEXT_SHERLOCK)).expect("Invalid UTF-8");
2123
// Decompression is much faster than compression, so inflate the data a bit
22-
let compressed_text = compress(&TEXT_SHERLOCK.repeat(20));
24+
let compressed_text = compress(&sherlock_text.repeat(20));
2325

2426
run_benchmark_group(|group| {
2527
group.register_benchmark("brotli-compress", || {
2628
let mut target_buffer: Vec<u8> = Vec::with_capacity(1024 * 1024);
2729
let mut params = BrotliEncoderParams::default();
2830
params.quality = 10;
2931

32+
let mut text = sherlock_text.as_bytes();
33+
3034
move || {
3135
let mut writer =
3236
brotli::CompressorWriter::with_params(&mut target_buffer, 4096, &params);
33-
std::io::copy(&mut TEXT_SHERLOCK.as_bytes(), &mut writer).unwrap();
37+
std::io::copy(&mut text, &mut writer).unwrap();
3438
writer.flush().unwrap();
3539
drop(writer);
3640
target_buffer

0 commit comments

Comments
 (0)