diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index 7921bb8f4..db908ecf6 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -2,16 +2,19 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use nu_cli::eval_source; use nu_parser::parse; use nu_plugin::{EncodingType, PluginResponse}; -use nu_protocol::{PipelineData, Span, Value}; +use nu_protocol::{engine::EngineState, PipelineData, Span, Value}; use nu_utils::{get_default_config, get_default_env}; +fn load_bench_commands() -> EngineState { + nu_command::add_shell_command_context(nu_cmd_lang::create_default_context()) +} // FIXME: All benchmarks live in this 1 file to speed up build times when benchmarking. // When the *_benchmarks functions were in different files, `cargo bench` would build // an executable for every single one - incredibly slowly. Would be nice to figure out // a way to split things up again. fn parser_benchmarks(c: &mut Criterion) { - let mut engine_state = nu_command::create_default_context(); + let mut engine_state = load_bench_commands(); // parsing config.nu breaks without PWD set engine_state.add_env_var( "PWD".into(), @@ -38,7 +41,7 @@ fn parser_benchmarks(c: &mut Criterion) { c.bench_function("eval default_env.nu", |b| { b.iter(|| { - let mut engine_state = nu_command::create_default_context(); + let mut engine_state = load_bench_commands(); let mut stack = nu_protocol::engine::Stack::new(); eval_source( &mut engine_state, @@ -53,7 +56,7 @@ fn parser_benchmarks(c: &mut Criterion) { c.bench_function("eval default_config.nu", |b| { b.iter(|| { - let mut engine_state = nu_command::create_default_context(); + let mut engine_state = load_bench_commands(); // parsing config.nu breaks without PWD set engine_state.add_env_var( "PWD".into(), @@ -75,7 +78,7 @@ fn parser_benchmarks(c: &mut Criterion) { fn eval_benchmarks(c: &mut Criterion) { c.bench_function("eval default_env.nu", |b| { b.iter(|| { - let mut engine_state = nu_command::create_default_context(); + let mut engine_state = load_bench_commands(); let mut stack = nu_protocol::engine::Stack::new(); eval_source( &mut engine_state, @@ -90,7 +93,7 @@ fn eval_benchmarks(c: &mut Criterion) { c.bench_function("eval default_config.nu", |b| { b.iter(|| { - let mut engine_state = nu_command::create_default_context(); + let mut engine_state = load_bench_commands(); // parsing config.nu breaks without PWD set engine_state.add_env_var( "PWD".into(),