Skip to content

Commit

Permalink
Add a benchmark for creating large uninit allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed May 28, 2024
1 parent 80cc120 commit 88a2496
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bench-cargo-miri/big-allocs/Cargo.lock

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

8 changes: 8 additions & 0 deletions bench-cargo-miri/big-allocs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "big-allocs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
13 changes: 13 additions & 0 deletions bench-cargo-miri/big-allocs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! This is a regression test for https://github.com/rust-lang/miri/issues/3637.
//! `Allocation`s are backed by a `Box<[u8]>`, which we create using `alloc_zeroed`, which should
//! make very large allocations cheap. But then we also need to not clone those `Allocation`s, or
//! we end up slow anyway.

fn main() {
// We can't use too big of an allocation or this code will encounter an allocation failure in
// CI. Since the allocation can't be huge, we need to do a few iterations so that the effect
// we're trying to measure is clearly visible above the interpreter's startup time.
for _ in 0..10 {
drop(Vec::<u8>::with_capacity(512 * 1024 * 1024));
}
}

0 comments on commit 88a2496

Please sign in to comment.