Skip to content

Commit 7eecd21

Browse files
authored
Update formatting and version strings for bench docs (#2381)
1 parent af1ea4b commit 7eecd21

File tree

1 file changed

+54
-42
lines changed

1 file changed

+54
-42
lines changed

runtime/reference/cli/bench.md

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ Deno.bench("URL parsing", () => {
2323

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

26-
```sh
27-
deno bench url_bench.ts
28-
cpu: Apple M1 Max
29-
runtime: deno 1.21.0 (aarch64-apple-darwin)
30-
31-
file:///dev/deno/url_bench.ts
32-
benchmark time (avg) (min … max) p75 p99 p995
33-
--------------------------------------------------- -----------------------------
34-
URL parsing 17.29 µs/iter (16.67 µs … 153.62 µs) 17.25 µs 18.92 µs 22.25 µs
26+
```shell
27+
$ deno bench url_bench.ts
28+
Check file:///path/to/url_bench.ts
29+
CPU | 12th Gen Intel(R) Core(TM) i3-12100
30+
Runtime | Deno 2.4.2 (x86_64-unknown-linux-gnu)
31+
32+
file:///path/to/url_bench.ts
33+
34+
| benchmark | time/iter (avg) | iter/s | (min … max) | p75 | p99 | p995 |
35+
| ------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |
36+
| URL parsing | 345.8 ns | 2,892,000 | (325.4 ns … 497.2 ns) | 346.9 ns | 443.2 ns | 497.2 ns |
3537
```
3638

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

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

161-
file:///dev/deno/time_bench.ts
162-
benchmark time (avg) (min … max) p75 p99 p995
163-
--------------------------------------------------------- -----------------------------
164-
Date.now() 125.24 ns/iter (118.98 ns … 559.95 ns) 123.62 ns 150.69 ns 156.63 ns
165-
performance.now() 2.67 µs/iter (2.64 µs … 2.82 µs) 2.67 µs 2.82 µs 2.82 µs
163+
file:///path/to/time_bench.ts
164+
165+
| benchmark | time/iter (avg) | iter/s | (min … max) | p75 | p99 | p995 |
166+
| ------------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |
167+
168+
group timing
169+
| Date.now() | 44.2 ns | 22,630,000 | ( 42.3 ns … 73.4 ns) | 44.0 ns | 54.1 ns | 55.1 ns |
170+
| performance.now() | 59.9 ns | 16,700,000 | ( 56.0 ns … 94.8 ns) | 60.7 ns | 76.6 ns | 79.5 ns |
166171

167172
summary
168173
Date.now()
169-
21.29x times faster than performance.now()
174+
1.35x faster than performance.now()
170175
```
171176

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

188-
```shell
193+
```bash
189194
# Run all benches in the current directory and all sub-directories
190195
deno bench
191196

@@ -199,7 +204,7 @@ deno bench my_bench.ts
199204
> ⚠️ If you want to pass additional CLI arguments to the bench files use `--` to
200205
> inform Deno that remaining arguments are scripts arguments.
201206
202-
```shell
207+
```bash
203208
# Pass additional arguments to the bench file
204209
deno bench my_bench.ts -- -e --foo --bar
205210
```
@@ -211,7 +216,7 @@ benching.
211216
To see all runtime options with `deno bench`, you can reference the command line
212217
help:
213218

214-
```shell
219+
```bash
215220
deno help bench
216221
```
217222

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

249-
```shell
254+
```bash
250255
deno bench --filter "bench" benchmarks/
251256
```
252257

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

256-
```shell
261+
```bash
257262
deno bench --filter "/bench-*\d/" benchmarks/
258263
```
259264

@@ -305,27 +310,34 @@ Deno.bench({
305310

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

308-
```
309-
$ deno bench --json bench_me.js
313+
```shell
314+
$ deno bench my_bench.ts --json
310315
{
311-
"runtime": "Deno/1.31.0 x86_64-apple-darwin",
312-
"cpu": "Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
316+
"version": 1,
317+
"runtime": "Deno/2.4.2 x86_64-unknown-linux-gnu",
318+
"cpu": "12th Gen Intel(R) Core(TM) i3-12100",
313319
"benches": [
314-
"origin": "file:///dev/bench_me.js",
315-
"group": null,
316-
"name": "Deno.UnsafePointerView#getUint32",
317-
"baseline": false,
318-
"result": {
319-
"ok": {
320-
"n": 49,
321-
"min": 1251.9348,
322-
"max": 1441.2696,
323-
"avg": 1308.7523755102038,
324-
"p75": 1324.1055,
325-
"p99": 1441.2696,
326-
"p995": 1441.2696,
327-
"p999": 1441.2696
328-
}
320+
{
321+
"origin": "file:///path/to/my_bench.ts",
322+
"group": null,
323+
"name": "Test",
324+
"baseline": false,
325+
"results": [
326+
{
327+
"ok": {
328+
"n": 51,
329+
"min": 946.7129,
330+
"max": 3024.3281,
331+
"avg": 1241.3926823529412,
332+
"p75": 1174.9718,
333+
"p99": 3024.3281,
334+
"p995": 3024.3281,
335+
"p999": 3024.3281,
336+
"highPrecision": false,
337+
"usedExplicitTimers": false
338+
}
339+
}
340+
]
329341
}
330342
]
331343
}

0 commit comments

Comments
 (0)