2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-03-07 20:16:32 -05:00
|
|
|
use deno_core::serde_json::json;
|
2023-01-12 20:59:13 -05:00
|
|
|
use deno_core::url::Url;
|
|
|
|
use test_util as util;
|
2024-02-12 19:13:14 -05:00
|
|
|
use test_util::itest;
|
|
|
|
use test_util::itest_flaky;
|
2023-02-27 15:52:49 -05:00
|
|
|
use util::assert_contains;
|
2023-06-06 17:07:46 -04:00
|
|
|
use util::assert_not_contains;
|
2023-02-23 10:58:10 -05:00
|
|
|
use util::env_vars_for_npm_tests;
|
2023-02-27 15:52:49 -05:00
|
|
|
use util::TestContext;
|
2024-03-07 20:16:32 -05:00
|
|
|
use util::TestContextBuilder;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
itest!(overloads {
|
|
|
|
args: "bench bench/overloads.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/overloads.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(meta {
|
|
|
|
args: "bench bench/meta.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/meta.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(pass {
|
|
|
|
args: "bench bench/pass.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/pass.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ignore {
|
|
|
|
args: "bench bench/ignore.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/ignore.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ignore_permissions {
|
|
|
|
args: "bench bench/ignore_permissions.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/ignore_permissions.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(fail {
|
|
|
|
args: "bench bench/fail.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/fail.out",
|
|
|
|
});
|
|
|
|
|
2023-06-07 06:27:25 -04:00
|
|
|
itest!(bench_formatting {
|
|
|
|
args: "bench bench/bench_formatting.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/bench_formatting.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(collect {
|
|
|
|
args: "bench --ignore=bench/collect/ignore bench/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/collect.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(load_unload {
|
|
|
|
args: "bench bench/load_unload.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/load_unload.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(interval {
|
|
|
|
args: "bench bench/interval.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/interval.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(quiet {
|
|
|
|
args: "bench --quiet bench/quiet.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/quiet.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(only {
|
|
|
|
args: "bench bench/only.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/only.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(multifile_summary {
|
2023-12-17 17:57:14 -05:00
|
|
|
args: "bench bench/group_baseline.ts bench/pass.ts bench/multiple_group.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/multifile_summary.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_check {
|
|
|
|
args: "bench --no-check bench/no_check.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/no_check.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(allow_all {
|
|
|
|
args: "bench --allow-all bench/allow_all.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/allow_all.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(allow_none {
|
|
|
|
args: "bench bench/allow_none.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/allow_none.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(exit_sanitizer {
|
|
|
|
args: "bench bench/exit_sanitizer.ts",
|
|
|
|
output: "bench/exit_sanitizer.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(clear_timeout {
|
|
|
|
args: "bench bench/clear_timeout.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/clear_timeout.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(finally_timeout {
|
|
|
|
args: "bench bench/finally_timeout.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/finally_timeout.out",
|
|
|
|
});
|
|
|
|
|
2023-05-03 17:10:51 -04:00
|
|
|
itest!(before_unload_prevent_default {
|
|
|
|
args: "bench --quiet bench/before_unload_prevent_default.ts",
|
|
|
|
output: "bench/before_unload_prevent_default.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(group_baseline {
|
|
|
|
args: "bench bench/group_baseline.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/group_baseline.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(unresolved_promise {
|
|
|
|
args: "bench bench/unresolved_promise.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/unresolved_promise.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(unhandled_rejection {
|
|
|
|
args: "bench bench/unhandled_rejection.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/unhandled_rejection.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(filter {
|
|
|
|
args: "bench --filter=foo bench/filter",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/filter.out",
|
|
|
|
});
|
|
|
|
|
2023-03-26 10:55:58 -04:00
|
|
|
itest!(no_run {
|
|
|
|
args: "bench --no-run bench/no_run.ts",
|
|
|
|
output: "bench/no_run.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(no_prompt_by_default {
|
|
|
|
args: "bench --quiet bench/no_prompt_by_default.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/no_prompt_by_default.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_prompt_with_denied_perms {
|
|
|
|
args: "bench --quiet --allow-read bench/no_prompt_with_denied_perms.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/no_prompt_with_denied_perms.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(check_local_by_default {
|
|
|
|
args: "bench --quiet bench/check_local_by_default.ts",
|
|
|
|
output: "bench/check_local_by_default.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(check_local_by_default2 {
|
|
|
|
args: "bench --quiet bench/check_local_by_default2.ts",
|
|
|
|
output: "bench/check_local_by_default2.out",
|
|
|
|
http_server: true,
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-07-31 06:02:59 -04:00
|
|
|
itest!(bench_explicit_start_end {
|
|
|
|
args: "bench --quiet -A bench/explicit_start_and_end.ts",
|
|
|
|
output: "bench/explicit_start_and_end.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-08-27 16:22:23 -04:00
|
|
|
itest_flaky!(bench_explicit_start_end_low_precision {
|
fix(bench): explicit timers don't force high precision measurements (#20272)
Disables `BenchContext::start()` and `BenchContext::end()` for low
precision benchmarks (less than 0.01s per iteration). Prints a warning
when they are used in such benchmarks, suggesting to remove them.
```ts
Deno.bench("noop", { group: "noops" }, () => {});
Deno.bench("noop with start/end", { group: "noops" }, (b) => {
b.start();
b.end();
});
```
Before:
```
cpu: 12th Gen Intel(R) Core(TM) i9-12900K
runtime: deno 1.36.2 (x86_64-unknown-linux-gnu)
file:///home/nayeem/projects/deno/temp3.ts
benchmark time (avg) iter/s (min … max) p75 p99 p995
----------------------------------------------------------------------------- -----------------------------
noop 2.63 ns/iter 380,674,131.4 (2.45 ns … 27.78 ns) 2.55 ns 4.03 ns 5.33 ns
noop with start and end 302.47 ns/iter 3,306,146.0 (200 ns … 151.2 µs) 300 ns 400 ns 400 ns
summary
noop
115.14x faster than noop with start and end
```
After:
```
cpu: 12th Gen Intel(R) Core(TM) i9-12900K
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
file:///home/nayeem/projects/deno/temp3.ts
benchmark time (avg) iter/s (min … max) p75 p99 p995
----------------------------------------------------------------------------- -----------------------------
noop 3.01 ns/iter 332,565,561.7 (2.73 ns … 29.54 ns) 2.93 ns 5.29 ns 7.45 ns
noop with start and end 7.73 ns/iter 129,291,091.5 (6.61 ns … 46.76 ns) 7.87 ns 13.12 ns 15.32 ns
Warning start() and end() calls in "noop with start and end" are ignored because it averages less than 0.01s per iteration. Remove them for better results.
summary
noop
2.57x faster than noop with start and end
```
2023-08-26 05:29:45 -04:00
|
|
|
args: "bench --quiet -A bench/explicit_start_and_end_low_precision.ts",
|
|
|
|
output: "bench/explicit_start_and_end_low_precision.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(bench_with_config {
|
|
|
|
args: "bench --config bench/collect/deno.jsonc bench/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/collect.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(bench_with_config2 {
|
|
|
|
args: "bench --config bench/collect/deno2.jsonc bench/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/collect2.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(bench_with_malformed_config {
|
|
|
|
args: "bench --config bench/collect/deno.malformed.jsonc",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "bench/collect_with_malformed_config.out",
|
|
|
|
});
|
|
|
|
|
2023-02-23 06:59:23 -05:00
|
|
|
itest!(json_output {
|
|
|
|
args: "bench --json bench/pass.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "bench/pass.json.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn recursive_permissions_pledge() {
|
2023-02-27 15:52:49 -05:00
|
|
|
let context = TestContext::default();
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
2023-04-27 18:37:03 -04:00
|
|
|
.args("bench bench/recursive_permissions_pledge.js")
|
2023-02-27 15:52:49 -05:00
|
|
|
.run();
|
2023-02-28 14:10:12 -05:00
|
|
|
output.assert_exit_code(1);
|
2023-02-27 15:52:49 -05:00
|
|
|
assert_contains!(
|
2023-03-06 09:16:50 -05:00
|
|
|
output.combined_output(),
|
2023-01-12 20:59:13 -05:00
|
|
|
"pledge test permissions called before restoring previous pledge"
|
2023-02-27 15:52:49 -05:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_protocol() {
|
|
|
|
let file_url =
|
|
|
|
Url::from_file_path(util::testdata_path().join("bench/file_protocol.ts"))
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
2023-02-27 15:52:49 -05:00
|
|
|
let context = TestContext::default();
|
2023-02-28 14:10:12 -05:00
|
|
|
context
|
2023-02-27 15:52:49 -05:00
|
|
|
.new_command()
|
|
|
|
.args(format!("bench bench/file_protocol.ts {file_url}"))
|
2023-02-28 14:10:12 -05:00
|
|
|
.run()
|
|
|
|
.assert_matches_file("bench/file_protocol.out");
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
2023-02-23 10:58:10 -05:00
|
|
|
|
|
|
|
itest!(package_json_basic {
|
|
|
|
args: "bench",
|
2023-02-25 08:56:39 -05:00
|
|
|
output: "package_json/basic/lib.bench.out",
|
2023-02-23 10:58:10 -05:00
|
|
|
envs: env_vars_for_npm_tests(),
|
|
|
|
http_server: true,
|
|
|
|
cwd: Some("package_json/basic"),
|
|
|
|
copy_temp_dir: Some("package_json/basic"),
|
|
|
|
exit_code: 0,
|
|
|
|
});
|
2023-03-13 17:04:00 -04:00
|
|
|
|
|
|
|
itest!(bench_lock {
|
|
|
|
args: "bench",
|
|
|
|
http_server: true,
|
|
|
|
cwd: Some("lockfile/basic"),
|
|
|
|
exit_code: 10,
|
|
|
|
output: "lockfile/basic/fail.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(bench_no_lock {
|
|
|
|
args: "bench --no-lock",
|
|
|
|
http_server: true,
|
|
|
|
cwd: Some("lockfile/basic"),
|
|
|
|
output: "lockfile/basic/bench.nolock.out",
|
|
|
|
});
|
2023-06-06 17:07:46 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn conditionally_loads_type_graph() {
|
|
|
|
let context = TestContext::default();
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("bench --reload -L debug run/type_directives_js_main.js")
|
|
|
|
.run();
|
|
|
|
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch() - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("bench --reload -L debug --no-check run/type_directives_js_main.js")
|
|
|
|
.run();
|
|
|
|
assert_not_contains!(output.combined_output(), "type_reference.d.ts");
|
|
|
|
}
|
2024-03-07 20:16:32 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_out_top_level_exclude_via_bench_unexclude() {
|
|
|
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"bench": {
|
|
|
|
"exclude": [ "!excluded.bench.ts" ]
|
|
|
|
},
|
|
|
|
"exclude": [ "excluded.bench.ts", "actually_excluded.bench.ts" ]
|
|
|
|
}));
|
|
|
|
|
|
|
|
temp_dir
|
|
|
|
.join("main.bench.ts")
|
|
|
|
.write("Deno.bench('test1', () => {});");
|
|
|
|
temp_dir
|
|
|
|
.join("excluded.bench.ts")
|
|
|
|
.write("Deno.bench('test2', () => {});");
|
|
|
|
temp_dir
|
|
|
|
.join("actually_excluded.bench.ts")
|
|
|
|
.write("Deno.bench('test3', () => {});");
|
|
|
|
|
|
|
|
let output = context.new_command().arg("bench").run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "main.bench.ts");
|
|
|
|
assert_contains!(output, "excluded.bench.ts");
|
|
|
|
assert_not_contains!(output, "actually_excluded.bench.ts");
|
|
|
|
}
|