Skip to content

Add a "cargo bench --debug" option #6446

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub fn cli() -> App {
subcommand("bench")
.setting(AppSettings::TrailingVarArg)
.about("Execute all benchmarks of a local package")
.arg(
Arg::with_name("debug")
.help("Build benchmarks in debug mode, without optimizations")
.long("debug")
.short("d")
)
.arg(
Arg::with_name("BENCHNAME")
.help("If specified, only run benches containing this string in their names"),
Expand Down Expand Up @@ -73,7 +79,7 @@ Compilation can be customized with the `bench` profile in the manifest.
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
let mut compile_opts = args.compile_options(config, CompileMode::Bench)?;
compile_opts.build_config.release = true;
compile_opts.build_config.release = !args.is_present("debug");

let ops = TestOptions {
no_run: args.is_present("no-run"),
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,37 @@ fn bench_multiple_targets() {
.run();
}

#[test]
fn cargo_bench_debug() {
if !is_nightly() {
return;
}

let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file(
"src/main.rs",
r#"
#![feature(test)]
#[cfg(test)]
extern crate test;
fn main() {}
#[bench] fn bench_hello(_b: &mut test::Bencher) {}
"#,
)
.build();

p.cargo("bench -d hello")
.with_stderr(
"\
[COMPILING] foo v0.5.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]",
)
.with_stdout_contains("test bench_hello ... bench: [..]")
.run();
}

#[test]
fn cargo_bench_verbose() {
if !is_nightly() {
Expand Down