Skip to content

Commit 53e9d0e

Browse files
authored
Merge pull request #1656 from Kobzol/runtime-svg
Add SVG parsing and rendering runtime benchmark
2 parents fe8e8e2 + c1f870e commit 53e9d0e

File tree

17 files changed

+1137
-247996
lines changed

17 files changed

+1137
-247996
lines changed

Cargo.lock

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

collector/benchlib/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ log = "0.4.17"
1414
env_logger = "0.10.0"
1515
clap = { version = "4.1", features = ["derive", "string"] }
1616
libc = "0.2"
17+
flate2 = { version = "1", optional = true }
1718

1819
[target.'cfg(target_os = "linux")'.dependencies]
1920
perf-event = "0.4.7"
21+
22+
[features]
23+
compression = ["dep:flate2"]

collector/benchlib/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ mod cli;
1818
pub mod comm;
1919
pub mod measure;
2020
pub mod process;
21+
mod utils;
22+
23+
#[cfg(feature = "compression")]
24+
pub use utils::decompress_file;

collector/benchlib/src/utils.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Decompresses the contents of a gzipped (.gz) file.
2+
#[cfg(feature = "compression")]
3+
pub fn decompress_file(contents: &[u8]) -> Vec<u8> {
4+
use std::io::Read;
5+
6+
let mut tar = flate2::bufread::GzDecoder::new(contents);
7+
let mut result = Vec::new();
8+
tar.read_to_end(&mut result)
9+
.expect("Cannot decompress file");
10+
11+
result
12+
}

collector/runtime-benchmarks/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ not print anything to `stdout`!
2222
Note that each benchmark group binary will be thus invoked twice per benchmarking collection. Keep this
2323
in mind so that the `main` function of the group doesn't perform too much work, which will be thrown
2424
away when it is invoked with the `list` argument.
25+
26+
## Benchmark input files
27+
Some benchmarks will need input files. Ideally, these should be stored directly inside this repository,
28+
e.g. in a `data` directory under the benchmark group workspace root. If some files are shared between
29+
multiple groups, you can put them in the `runtime-benchmarks/data` directory. To keep benchmarks
30+
self-contained, consider including the input files directly into the binary using the `include_bytes!`
31+
or `include_str!` macros.
32+
33+
Try to keep the sizes of input files reasonable. If you want to increase their size for the benchmark,
34+
you can repeat their contents at the beginning of the benchmark run (in `main`). If the file has a
35+
format that is not easily repeatable it is large (e.g. larger than 1 MiB), consider compressing it
36+
using `gzip <file>` and them decompressing it in `main` using `benchlib::decompress_file`.

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)