Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile allocations in benchmarks #40

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- [`AllocProfiler`](https://docs.rs/divan/0.1.6/divan/struct.AllocProfiler.html)
allocator that tracks allocation counts and sizes during benchmarks.

## [0.1.5] - 2023-12-05

### Added
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ readme = "README.md"
[dependencies]
divan-macros = { version = "0.1.5", path = "macros" }

cfg-if = "1"
clap = { version = "4", default-features = false, features = ["std", "env"] }
condtype = "1.3"
regex = { package = "regex-lite", version = "0.1", default-features = false, features = ["std", "string"] }

[target.'cfg(target_os = "macos")'.dependencies]
libc = { workspace = true }

[dev-dependencies]
mimalloc = "0.1"

[features]
default = ["wrap_help"]
help = ["clap/help"]
Expand All @@ -32,3 +39,4 @@ members = ["macros", "examples", "internal_benches"]

[workspace.dependencies]
divan = { path = "." }
libc = "0.2.148"
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sha3 = { version = "0.10", optional = true }
twox-hash = { version = "1.6", optional = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2.148"
libc = { workspace = true }

[target.'cfg(any(windows, target_os = "linux", target_os = "android"))'.dependencies]
winapi = { version = "0.3.9", features = ["processthreadsapi"] }
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

use std::collections::{BTreeSet, BinaryHeap, HashSet, LinkedList, VecDeque};

use divan::{black_box, Bencher};
use divan::{black_box, AllocProfiler, Bencher};

mod util;

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}
Expand Down
4 changes: 4 additions & 0 deletions examples/benches/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
//! ```

use digest::Digest;
use divan::AllocProfiler;

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
//! cargo bench -q -p examples --bench image --features image
//! ```

use divan::{black_box, counter::BytesCount, Bencher};
use divan::{black_box, counter::BytesCount, AllocProfiler, Bencher};
use image::{GenericImage, ImageBuffer, Rgba};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use std::panic;

use divan::{black_box, black_box_drop};
use divan::{black_box, black_box_drop, AllocProfiler};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
// Silence panics.
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ use std::{
hash::BuildHasher,
};

use divan::{black_box_drop, Bencher};
use divan::{black_box_drop, AllocProfiler, Bencher};
use fastrand::Rng;
use ordsearch::OrderedCollection;

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::Divan::from_args()
.items_count(
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
//! cargo bench -q -p examples --bench sort
//! ```

use divan::Bencher;
use divan::{AllocProfiler, Bencher};
use rayon::slice::ParallelSliceMut;

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use divan::{
black_box, black_box_drop,
counter::{BytesCount, CharsCount},
Bencher,
AllocProfiler, Bencher,
};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use std::{
thread::{Thread, ThreadId},
};

use divan::{black_box, black_box_drop, Bencher};
use divan::{black_box, black_box_drop, AllocProfiler, Bencher};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
Expand Down
5 changes: 4 additions & 1 deletion examples/benches/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use std::time::{Instant, SystemTime};

use divan::Bencher;
use divan::{AllocProfiler, Bencher};

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
Expand Down
5 changes: 5 additions & 0 deletions internal_benches/benches/internals.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use divan::AllocProfiler;

#[global_allocator]
static GLOBAL_ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}
Loading