rename benchmark to time (#8018)
# Description This PR renames the `benchmark` command to the `time` command. # User-Facing Changes new command name # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
parent
23dfaa2933
commit
b9106b633b
|
@ -172,12 +172,12 @@ pub fn create_default_context() -> EngineState {
|
||||||
|
|
||||||
// System
|
// System
|
||||||
bind_command! {
|
bind_command! {
|
||||||
Benchmark,
|
|
||||||
Complete,
|
Complete,
|
||||||
Explain,
|
Explain,
|
||||||
External,
|
External,
|
||||||
NuCheck,
|
NuCheck,
|
||||||
Sys,
|
Sys,
|
||||||
|
TimeIt,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
mod benchmark;
|
|
||||||
mod complete;
|
mod complete;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
mod exec;
|
mod exec;
|
||||||
|
@ -15,9 +14,9 @@ mod ps;
|
||||||
mod registry_query;
|
mod registry_query;
|
||||||
mod run_external;
|
mod run_external;
|
||||||
mod sys;
|
mod sys;
|
||||||
|
mod timeit;
|
||||||
mod which_;
|
mod which_;
|
||||||
|
|
||||||
pub use benchmark::Benchmark;
|
|
||||||
pub use complete::Complete;
|
pub use complete::Complete;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub use exec::Exec;
|
pub use exec::Exec;
|
||||||
|
@ -34,4 +33,5 @@ pub use ps::Ps;
|
||||||
pub use registry_query::RegistryQuery;
|
pub use registry_query::RegistryQuery;
|
||||||
pub use run_external::{External, ExternalCommand};
|
pub use run_external::{External, ExternalCommand};
|
||||||
pub use sys::Sys;
|
pub use sys::Sys;
|
||||||
|
pub use timeit::TimeIt;
|
||||||
pub use which_::Which;
|
pub use which_::Which;
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use nu_engine::{eval_block, CallExt};
|
use nu_engine::{eval_block, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
|
||||||
use nu_protocol::engine::{Closure, Command, EngineState, Stack};
|
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
|
ast::Call,
|
||||||
|
engine::{Closure, Command, EngineState, Stack},
|
||||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
|
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
|
||||||
Value,
|
Value,
|
||||||
};
|
};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Benchmark;
|
pub struct TimeIt;
|
||||||
|
|
||||||
impl Command for Benchmark {
|
impl Command for TimeIt {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"benchmark"
|
"timeit"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -21,7 +20,7 @@ impl Command for Benchmark {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> nu_protocol::Signature {
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
Signature::build("benchmark")
|
Signature::build("timeit")
|
||||||
.required(
|
.required(
|
||||||
"closure",
|
"closure",
|
||||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),
|
SyntaxShape::Closure(Some(vec![SyntaxShape::Any])),
|
||||||
|
@ -35,6 +34,10 @@ impl Command for Benchmark {
|
||||||
.category(Category::System)
|
.category(Category::System)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
vec!["timing", "timer", "benchmark", "measure"]
|
||||||
|
}
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
|
@ -88,13 +91,13 @@ impl Command for Benchmark {
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Benchmarks a command within a closure",
|
description: "Times a command within a closure",
|
||||||
example: "benchmark { sleep 500ms }",
|
example: "timeit { sleep 500ms }",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Benchmark a command using an existing input",
|
description: "Times a command using an existing input",
|
||||||
example: "fetch https://www.nushell.sh/book/ | benchmark { split chars }",
|
example: "http get https://www.nushell.sh/book/ | timeit { split chars }",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -102,13 +105,13 @@ impl Command for Benchmark {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
// Due to difficulty in observing side-effects from benchmark closures,
|
// Due to difficulty in observing side-effects from time closures,
|
||||||
// checks that the closures have run correctly must use the filesystem.
|
// checks that the closures have run correctly must use the filesystem.
|
||||||
fn test_benchmark_closure() {
|
fn test_time_closure() {
|
||||||
use nu_test_support::{nu, nu_repl_code, playground::Playground};
|
use nu_test_support::{nu, nu_repl_code, playground::Playground};
|
||||||
Playground::setup("test_benchmark_closure", |dirs, _| {
|
Playground::setup("test_time_closure", |dirs, _| {
|
||||||
let inp = [
|
let inp = [
|
||||||
r#"[2 3 4] | benchmark { to nuon | save foo.txt }"#,
|
r#"[2 3 4] | timeit { to nuon | save foo.txt }"#,
|
||||||
"open foo.txt",
|
"open foo.txt",
|
||||||
];
|
];
|
||||||
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));
|
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));
|
||||||
|
@ -118,11 +121,11 @@ fn test_benchmark_closure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_benchmark_closure_2() {
|
fn test_time_closure_2() {
|
||||||
use nu_test_support::{nu, nu_repl_code, playground::Playground};
|
use nu_test_support::{nu, nu_repl_code, playground::Playground};
|
||||||
Playground::setup("test_benchmark_closure", |dirs, _| {
|
Playground::setup("test_time_closure", |dirs, _| {
|
||||||
let inp = [
|
let inp = [
|
||||||
r#"[2 3 4] | benchmark {|e| {result: $e} | to nuon | save foo.txt }"#,
|
r#"[2 3 4] | timeit {|e| {result: $e} | to nuon | save foo.txt }"#,
|
||||||
"open foo.txt",
|
"open foo.txt",
|
||||||
];
|
];
|
||||||
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));
|
let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp));
|
|
@ -116,8 +116,8 @@ fn command_not_found_error_suggests_search_term() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn command_not_found_error_suggests_typo_fix() {
|
fn command_not_found_error_suggests_typo_fix() {
|
||||||
let actual = nu!(cwd: ".", "benhcmark { echo 'foo'}");
|
let actual = nu!(cwd: ".", "benchmark { echo 'foo'}");
|
||||||
assert!(actual.err.contains("benchmark"));
|
assert!(actual.err.contains("timeit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user