@@ -23,15 +23,17 @@ Deno.bench("URL parsing", () => {
23
23
24
24
Secondly, run the benchmark using the ` deno bench ` subcommand.
25
25
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 |
35
37
```
36
38
37
39
## Writing benchmarks
@@ -153,20 +155,23 @@ Deno.bench("performance.now()", { group: "timing" }, () => {
153
155
});
154
156
```
155
157
156
- ``` shellsesssion
158
+ ``` shell
157
159
$ 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 )
160
162
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 |
166
171
167
172
summary
168
173
Date.now ()
169
- 21.29x times faster than performance.now()
174
+ 1.35x faster than performance.now ()
170
175
```
171
176
172
177
You can specify multiple groups in the same file.
@@ -185,7 +190,7 @@ The glob expands to:
185
190
- or files ending with ` .bench.{ts, tsx, mts, js, mjs, jsx} ` ,
186
191
- or files ending with ` _bench.{ts, tsx, mts, js, mjs, jsx} `
187
192
188
- ``` shell
193
+ ``` bash
189
194
# Run all benches in the current directory and all sub-directories
190
195
deno bench
191
196
@@ -199,7 +204,7 @@ deno bench my_bench.ts
199
204
> ⚠️ If you want to pass additional CLI arguments to the bench files use ` -- ` to
200
205
> inform Deno that remaining arguments are scripts arguments.
201
206
202
- ``` shell
207
+ ``` bash
203
208
# Pass additional arguments to the bench file
204
209
deno bench my_bench.ts -- -e --foo --bar
205
210
```
@@ -211,7 +216,7 @@ benching.
211
216
To see all runtime options with ` deno bench ` , you can reference the command line
212
217
help:
213
218
214
- ``` shell
219
+ ``` bash
215
220
deno help bench
216
221
```
217
222
@@ -246,14 +251,14 @@ Deno.bench({
246
251
This command will run all of these benches because they all contain the word
247
252
"bench".
248
253
249
- ``` shell
254
+ ``` bash
250
255
deno bench --filter " bench" benchmarks/
251
256
```
252
257
253
258
On the flip side, the following command uses a pattern and will run the second
254
259
and third benchmarks.
255
260
256
- ``` shell
261
+ ``` bash
257
262
deno bench --filter " /bench-*\d/" benchmarks/
258
263
```
259
264
@@ -305,27 +310,34 @@ Deno.bench({
305
310
306
311
To retrieve the output as JSON, use the ` --json ` flag:
307
312
308
- ```
309
- $ deno bench --json bench_me.js
313
+ ``` shell
314
+ $ deno bench my_bench.ts --json
310
315
{
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" ,
313
319
" 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
+ ]
329
341
}
330
342
]
331
343
}
0 commit comments