1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

feat(init): Generate main_bench.ts by default (#16786)

This commit changes "deno init" to generate "main_bench.ts" file
which scaffold two example bench cases.
This commit is contained in:
sigmaSd 2022-12-10 00:34:08 +01:00 committed by GitHub
parent 6794d9fe5d
commit 4eb8e875fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 0 deletions

View file

@ -30,6 +30,7 @@ mod init {
assert_contains!(stderr, "deno run main.ts");
assert_contains!(stderr, "deno task dev");
assert_contains!(stderr, "deno test");
assert_contains!(stderr, "deno bench");
assert!(cwd.join("deno.jsonc").exists());
@ -60,6 +61,18 @@ mod init {
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert_contains!(stdout, "1 passed");
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd
.current_dir(cwd)
.env("NO_COLOR", "1")
.arg("bench")
.stdout(Stdio::piped())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
}
#[test]
@ -85,6 +98,7 @@ mod init {
assert_contains!(stderr, "deno run main.ts");
assert_contains!(stderr, "deno task dev");
assert_contains!(stderr, "deno test");
assert_contains!(stderr, "deno bench");
assert!(cwd.join("my_dir/deno.jsonc").exists());
@ -116,6 +130,19 @@ mod init {
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert_contains!(stdout, "1 passed");
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd
.current_dir(cwd)
.env("NO_COLOR", "1")
.arg("bench")
.arg("my_dir/main_bench.ts")
.stdout(Stdio::piped())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
}
#[test]
@ -166,5 +193,17 @@ mod init {
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert_contains!(stdout, "1 passed");
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd
.current_dir(cwd)
.env("NO_COLOR", "1")
.arg("bench")
.stdout(Stdio::piped())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
}
}

View file

@ -40,6 +40,8 @@ pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> {
let main_test_ts = include_str!("./templates/main_test.ts")
.replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL.as_str());
create_file(&dir, "main_test.ts", &main_test_ts)?;
let main_bench_ts = include_str!("./templates/main_bench.ts");
create_file(&dir, "main_bench.ts", main_bench_ts)?;
create_file(&dir, "deno.jsonc", include_str!("./templates/deno.jsonc"))?;
@ -62,5 +64,8 @@ pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> {
info!("");
info!(" {}", colors::gray("// Run the tests"));
info!(" deno test");
info!("");
info!(" {}", colors::gray("// Run the benchmarks"));
info!(" deno bench");
Ok(())
}

View file

@ -0,0 +1,9 @@
import { add } from "./main.ts";
Deno.bench(function addSmall() {
add(1, 2);
});
Deno.bench(function addBig() {
add(2 ** 32, 2 ** 32);
});