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

@ -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);
});