diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 6ffadef4a0..d046510c0a 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 e1fe95ac6f..3f07ac856e 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 d9ba5e2c75..0a29f553c7 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 da23439b2f..7e640a1fa9 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]