Skip to content

Update formatting and version strings for bench docs #2381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 54 additions & 42 deletions runtime/reference/cli/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ Deno.bench("URL parsing", () => {

Secondly, run the benchmark using the `deno bench` subcommand.

```sh
deno bench url_bench.ts
cpu: Apple M1 Max
runtime: deno 1.21.0 (aarch64-apple-darwin)

file:///dev/deno/url_bench.ts
benchmark time (avg) (min … max) p75 p99 p995
--------------------------------------------------- -----------------------------
URL parsing 17.29 µs/iter (16.67 µs … 153.62 µs) 17.25 µs 18.92 µs 22.25 µs
```shell
$ deno bench url_bench.ts
Check file:///path/to/url_bench.ts
CPU | 12th Gen Intel(R) Core(TM) i3-12100
Runtime | Deno 2.4.2 (x86_64-unknown-linux-gnu)

file:///path/to/url_bench.ts

| benchmark | time/iter (avg) | iter/s | (min … max) | p75 | p99 | p995 |
| ------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |
| URL parsing | 345.8 ns | 2,892,000 | (325.4 ns … 497.2 ns) | 346.9 ns | 443.2 ns | 497.2 ns |
```

## Writing benchmarks
Expand Down Expand Up @@ -153,20 +155,23 @@ Deno.bench("performance.now()", { group: "timing" }, () => {
});
```

```shellsesssion
```shell
$ deno bench time_bench.ts
cpu: Apple M1 Max
runtime: deno 1.21.0 (aarch64-apple-darwin)
CPU | 12th Gen Intel(R) Core(TM) i3-12100
Runtime | Deno 2.4.2 (x86_64-unknown-linux-gnu)

file:///dev/deno/time_bench.ts
benchmark time (avg) (min … max) p75 p99 p995
--------------------------------------------------------- -----------------------------
Date.now() 125.24 ns/iter (118.98 ns … 559.95 ns) 123.62 ns 150.69 ns 156.63 ns
performance.now() 2.67 µs/iter (2.64 µs … 2.82 µs) 2.67 µs 2.82 µs 2.82 µs
file:///path/to/time_bench.ts

| benchmark | time/iter (avg) | iter/s | (min … max) | p75 | p99 | p995 |
| ------------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |

group timing
| Date.now() | 44.2 ns | 22,630,000 | ( 42.3 ns … 73.4 ns) | 44.0 ns | 54.1 ns | 55.1 ns |
| performance.now() | 59.9 ns | 16,700,000 | ( 56.0 ns … 94.8 ns) | 60.7 ns | 76.6 ns | 79.5 ns |

summary
Date.now()
21.29x times faster than performance.now()
1.35x faster than performance.now()
```

You can specify multiple groups in the same file.
Expand All @@ -185,7 +190,7 @@ The glob expands to:
- or files ending with `.bench.{ts, tsx, mts, js, mjs, jsx}`,
- or files ending with `_bench.{ts, tsx, mts, js, mjs, jsx}`

```shell
```bash
# Run all benches in the current directory and all sub-directories
deno bench

Expand All @@ -199,7 +204,7 @@ deno bench my_bench.ts
> ⚠️ If you want to pass additional CLI arguments to the bench files use `--` to
> inform Deno that remaining arguments are scripts arguments.

```shell
```bash
# Pass additional arguments to the bench file
deno bench my_bench.ts -- -e --foo --bar
```
Expand All @@ -211,7 +216,7 @@ benching.
To see all runtime options with `deno bench`, you can reference the command line
help:

```shell
```bash
deno help bench
```

Expand Down Expand Up @@ -246,14 +251,14 @@ Deno.bench({
This command will run all of these benches because they all contain the word
"bench".

```shell
```bash
deno bench --filter "bench" benchmarks/
```

On the flip side, the following command uses a pattern and will run the second
and third benchmarks.

```shell
```bash
deno bench --filter "/bench-*\d/" benchmarks/
```

Expand Down Expand Up @@ -305,27 +310,34 @@ Deno.bench({

To retrieve the output as JSON, use the `--json` flag:

```
$ deno bench --json bench_me.js
```shell
$ deno bench my_bench.ts --json
{
"runtime": "Deno/1.31.0 x86_64-apple-darwin",
"cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
"version": 1,
"runtime": "Deno/2.4.2 x86_64-unknown-linux-gnu",
"cpu": "12th Gen Intel(R) Core(TM) i3-12100",
"benches": [
"origin": "file:///dev/bench_me.js",
"group": null,
"name": "Deno.UnsafePointerView#getUint32",
"baseline": false,
"result": {
"ok": {
"n": 49,
"min": 1251.9348,
"max": 1441.2696,
"avg": 1308.7523755102038,
"p75": 1324.1055,
"p99": 1441.2696,
"p995": 1441.2696,
"p999": 1441.2696
}
{
"origin": "file:///path/to/my_bench.ts",
"group": null,
"name": "Test",
"baseline": false,
"results": [
{
"ok": {
"n": 51,
"min": 946.7129,
"max": 3024.3281,
"avg": 1241.3926823529412,
"p75": 1174.9718,
"p99": 3024.3281,
"p995": 3024.3281,
"p999": 3024.3281,
"highPrecision": false,
"usedExplicitTimers": false
}
}
]
}
]
}
Expand Down
Loading