Skip to content

Commit 9a5818a

Browse files
authored
Merge pull request #2175 from Kobzol/include-blob
Add `include-blob` secondary benchmark
2 parents 00be711 + 4be9df6 commit 9a5818a

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

collector/compile-benchmarks/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ compiler in interesting ways.
7979
- **externs**: A large number of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448).
8080
- **helloworld-tiny**: A trivial program optimized with flags that should reduce binary size.
8181
Gives a lower bound on compiled binary size.
82+
- **include-blob**: Stress test for including binary and string blobs with `include_str!` and
83+
`include_bytes!`. Its build script generates 30 MiB blobs that are then included into the program.
8284
- **issue-46449**: A small program that caused [poor
8385
performance](https://github.com/rust-lang/rust/issues/46449) in the past.
8486
- **issue-58319**: A small program that caused [poor

collector/compile-benchmarks/REUSE.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ path = "image-0.25.6/**"
130130
SPDX-FileCopyrightText = "The image-rs Developers"
131131
SPDX-License-Identifier = "MIT"
132132

133+
[[annotations]]
134+
path = "include-blob/**"
135+
SPDX-FileCopyrightText = "The Rust Project Developers (see https://thanks.rust-lang.org)"
136+
SPDX-License-Identifier = "MIT OR Apache-2.0"
137+
133138
[[annotations]]
134139
path = "inflate/**"
135140
SPDX-FileCopyrightText = "inflate contributors"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/src/main.rs b/src/main.rs
2+
index 9cb1671e..fc854410 100644
3+
--- a/src/main.rs
4+
+++ b/src/main.rs
5+
@@ -6,5 +6,5 @@ fn main() {
6+
"Binary blob last element: {}",
7+
BLOB_BINARY[BLOB_BINARY.len() - 1]
8+
);
9+
- println!("String blob: {BLOB_STRING}");
10+
+ println!("String blob contents: {BLOB_STRING}");
11+
}

collector/compile-benchmarks/include-blob/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "include-blob"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
8+
[workspace]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::path::PathBuf;
2+
3+
fn main() {
4+
let byte_count = 30usize * 1024 * 1024;
5+
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR is missing"));
6+
7+
// Generate large (30 MiB) blobs of data to include into the resulting program
8+
let binary_data: Vec<u8> = (0..byte_count).map(|v| (v % 256) as u8).collect();
9+
std::fs::write(out_dir.join("blob-binary"), binary_data).expect("cannot write binary blob");
10+
11+
let string_data: String = ('a'..'z').cycle().take(byte_count).collect();
12+
std::fs::write(out_dir.join("blob-string"), string_data).expect("cannot write string blob");
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"category": "secondary",
3+
"artifact": "binary"
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BLOB_BINARY: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/blob-binary"));
2+
const BLOB_STRING: &str = include_str!(concat!(env!("OUT_DIR"), "/blob-string"));
3+
4+
fn main() {
5+
println!("Binary blob: {BLOB_BINARY:?}");
6+
println!("String blob: {BLOB_STRING:?}");
7+
}

0 commit comments

Comments
 (0)