From b9106b633bfce6600dd8d0c1df7e609268ed6f4e Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 11 Feb 2023 12:57:48 -0600 Subject: [PATCH] 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. --- crates/nu-command/src/default_context.rs | 2 +- crates/nu-command/src/system/mod.rs | 4 +- .../src/system/{benchmark.rs => timeit.rs} | 41 ++++++++++--------- tests/shell/pipeline/commands/external.rs | 4 +- 4 files changed, 27 insertions(+), 24 deletions(-) rename crates/nu-command/src/system/{benchmark.rs => timeit.rs} (78%) diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 6ffadef4a..d046510c0 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -172,12 +172,12 @@ pub fn create_default_context() -> EngineState { // System bind_command! { - Benchmark, Complete, Explain, External, NuCheck, Sys, + TimeIt, }; #[cfg(unix)] diff --git a/crates/nu-command/src/system/mod.rs b/crates/nu-command/src/system/mod.rs index e1fe95ac6..3f07ac856 100644 --- a/crates/nu-command/src/system/mod.rs +++ b/crates/nu-command/src/system/mod.rs @@ -1,4 +1,3 @@ -mod benchmark; mod complete; #[cfg(unix)] mod exec; @@ -15,9 +14,9 @@ mod ps; mod registry_query; mod run_external; mod sys; +mod timeit; mod which_; -pub use benchmark::Benchmark; pub use complete::Complete; #[cfg(unix)] pub use exec::Exec; @@ -34,4 +33,5 @@ pub use ps::Ps; pub use registry_query::RegistryQuery; pub use run_external::{External, ExternalCommand}; pub use sys::Sys; +pub use timeit::TimeIt; pub use which_::Which; diff --git a/crates/nu-command/src/system/benchmark.rs b/crates/nu-command/src/system/timeit.rs similarity index 78% rename from crates/nu-command/src/system/benchmark.rs rename to crates/nu-command/src/system/timeit.rs index d9ba5e2c7..0a29f553c 100644 --- a/crates/nu-command/src/system/benchmark.rs +++ b/crates/nu-command/src/system/timeit.rs @@ -1,19 +1,18 @@ -use std::time::Instant; - use nu_engine::{eval_block, CallExt}; -use nu_protocol::ast::Call; -use nu_protocol::engine::{Closure, Command, EngineState, Stack}; use nu_protocol::{ + ast::Call, + engine::{Closure, Command, EngineState, Stack}, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, }; +use std::time::Instant; #[derive(Clone)] -pub struct Benchmark; +pub struct TimeIt; -impl Command for Benchmark { +impl Command for TimeIt { fn name(&self) -> &str { - "benchmark" + "timeit" } fn usage(&self) -> &str { @@ -21,7 +20,7 @@ impl Command for Benchmark { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("benchmark") + Signature::build("timeit") .required( "closure", SyntaxShape::Closure(Some(vec![SyntaxShape::Any])), @@ -35,6 +34,10 @@ impl Command for Benchmark { .category(Category::System) } + fn search_terms(&self) -> Vec<&str> { + vec!["timing", "timer", "benchmark", "measure"] + } + fn run( &self, engine_state: &EngineState, @@ -88,13 +91,13 @@ impl Command for Benchmark { fn examples(&self) -> Vec { vec![ Example { - description: "Benchmarks a command within a closure", - example: "benchmark { sleep 500ms }", + description: "Times a command within a closure", + example: "timeit { sleep 500ms }", result: None, }, Example { - description: "Benchmark a command using an existing input", - example: "fetch https://www.nushell.sh/book/ | benchmark { split chars }", + description: "Times a command using an existing input", + example: "http get https://www.nushell.sh/book/ | timeit { split chars }", result: None, }, ] @@ -102,13 +105,13 @@ impl Command for Benchmark { } #[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. -fn test_benchmark_closure() { +fn test_time_closure() { use nu_test_support::{nu, nu_repl_code, playground::Playground}; - Playground::setup("test_benchmark_closure", |dirs, _| { + Playground::setup("test_time_closure", |dirs, _| { 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", ]; let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp)); @@ -118,11 +121,11 @@ fn test_benchmark_closure() { } #[test] -fn test_benchmark_closure_2() { +fn test_time_closure_2() { use nu_test_support::{nu, nu_repl_code, playground::Playground}; - Playground::setup("test_benchmark_closure", |dirs, _| { + Playground::setup("test_time_closure", |dirs, _| { 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", ]; let actual_repl = nu!(cwd: dirs.test(), nu_repl_code(&inp)); diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index da23439b2..7e640a1fa 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -116,8 +116,8 @@ fn command_not_found_error_suggests_search_term() { #[test] fn command_not_found_error_suggests_typo_fix() { - let actual = nu!(cwd: ".", "benhcmark { echo 'foo'}"); - assert!(actual.err.contains("benchmark")); + let actual = nu!(cwd: ".", "benchmark { echo 'foo'}"); + assert!(actual.err.contains("timeit")); } #[test]