1
- # Node.js core benchmark
1
+ # How to Write and Run Benchmarks in Node.js Core
2
2
3
- This folder contains benchmarks to measure the performance of the Node.js APIs.
4
-
5
- ## Table of Content
3
+ ## Table of Contents
6
4
7
5
* [ Prerequisites] ( #prerequisites )
6
+ * [ HTTP Benchmark Requirements] ( #http-benchmark-requirements )
7
+ * [ Benchmark Analysis Requirements] ( #benchmark-analysis-requirements )
8
8
* [ Running benchmarks] ( #running-benchmarks )
9
- * [ Running individual benchmarks] ( #running-individual-benchmarks )
10
- * [ Running all benchmarks] ( #running-all-benchmarks )
11
- * [ Comparing node versions] ( #comparing-node -versions )
12
- * [ Comparing parameters] ( #comparing-parameters )
9
+ * [ Running individual benchmarks] ( #running-individual-benchmarks )
10
+ * [ Running all benchmarks] ( #running-all-benchmarks )
11
+ * [ Comparing Node.js versions] ( #comparing-nodejs -versions )
12
+ * [ Comparing parameters] ( #comparing-parameters )
13
13
* [ Creating a benchmark] ( #creating-a-benchmark )
14
+ * [ Basics of a benchmark] ( #basics-of-a-benchmark )
15
+ * [ Creating an HTTP benchmark] ( #creating-an-http-benchmark )
14
16
15
17
## Prerequisites
16
18
19
+ Basic Unix tools are required for some benchmarks.
20
+ [ Git for Windows] [ git-for-windows ] includes Git Bash and the necessary tools,
21
+ which need to be included in the global Windows ` PATH ` .
22
+
23
+ ### HTTP Benchmark Requirements
24
+
17
25
Most of the HTTP benchmarks require a benchmarker to be installed, this can be
18
26
either [ ` wrk ` ] [ wrk ] or [ ` autocannon ` ] [ autocannon ] .
19
27
20
- ` Autocannon ` is a Node script that can be installed using
21
- ` npm install -g autocannon ` . It will use the Node executable that is in the
28
+ ` Autocannon ` is a Node.js script that can be installed using
29
+ ` npm install -g autocannon ` . It will use the Node.js executable that is in the
22
30
path, hence if you want to compare two HTTP benchmark runs make sure that the
23
- Node version in the path is not altered.
31
+ Node.js version in the path is not altered.
24
32
25
33
` wrk ` may be available through your preferred package manager. If not, you can
26
34
easily build it [ from source] [ wrk ] via ` make ` .
@@ -34,9 +42,7 @@ benchmarker to be used by providing it as an argument, e. g.:
34
42
35
43
` node benchmark/http/simple.js benchmarker=autocannon `
36
44
37
- Basic Unix tools are required for some benchmarks.
38
- [ Git for Windows] [ git-for-windows ] includes Git Bash and the necessary tools,
39
- which need to be included in the global Windows ` PATH ` .
45
+ ### Benchmark Analysis Requirements
40
46
41
47
To analyze the results ` R ` should be installed. Check you package manager or
42
48
download it from https://www.r-project.org/ .
@@ -50,7 +56,6 @@ install.packages("ggplot2")
50
56
install.packages(" plyr" )
51
57
```
52
58
53
- ### CRAN Mirror Issues
54
59
In the event you get a message that you need to select a CRAN mirror first.
55
60
56
61
You can specify a mirror by adding in the repo parameter.
@@ -108,7 +113,8 @@ buffers/buffer-tostring.js n=10000000 len=1024 arg=false: 3783071.1678948295
108
113
### Running all benchmarks
109
114
110
115
Similar to running individual benchmarks, a group of benchmarks can be executed
111
- by using the ` run.js ` tool. Again this does not provide the statistical
116
+ by using the ` run.js ` tool. To see how to use this script,
117
+ run ` node benchmark/run.js ` . Again this does not provide the statistical
112
118
information to make any conclusions.
113
119
114
120
``` console
@@ -135,18 +141,19 @@ It is possible to execute more groups by adding extra process arguments.
135
141
$ node benchmark/run.js arrays buffers
136
142
```
137
143
138
- ### Comparing node versions
144
+ ### Comparing Node.js versions
139
145
140
- To compare the effect of a new node version use the ` compare.js ` tool. This
146
+ To compare the effect of a new Node.js version use the ` compare.js ` tool. This
141
147
will run each benchmark multiple times, making it possible to calculate
142
- statistics on the performance measures.
148
+ statistics on the performance measures. To see how to use this script,
149
+ run ` node benchmark/compare.js ` .
143
150
144
151
As an example on how to check for a possible performance improvement, the
145
152
[ #5134 ] ( https://github.com/nodejs/node/pull/5134 ) pull request will be used as
146
153
an example. This pull request _ claims_ to improve the performance of the
147
154
` string_decoder ` module.
148
155
149
- First build two versions of node , one from the master branch (here called
156
+ First build two versions of Node.js , one from the master branch (here called
150
157
` ./node-master ` ) and another with the pull request applied (here called
151
158
` ./node-pr-5135 ` ).
152
159
@@ -219,7 +226,8 @@ It can be useful to compare the performance for different parameters, for
219
226
example to analyze the time complexity.
220
227
221
228
To do this use the ` scatter.js ` tool, this will run a benchmark multiple times
222
- and generate a csv with the results.
229
+ and generate a csv with the results. To see how to use this script,
230
+ run ` node benchmark/scatter.js ` .
223
231
224
232
``` console
225
233
$ node benchmark/scatter.js benchmark/string_decoder/string-decoder.js > scatter.csv
@@ -286,6 +294,8 @@ chunk encoding mean confidence.interval
286
294
287
295
## Creating a benchmark
288
296
297
+ ### Basics of a benchmark
298
+
289
299
All benchmarks use the ` require('../common.js') ` module. This contains the
290
300
` createBenchmark(main, configs[, options]) ` method which will setup your
291
301
benchmark.
@@ -369,7 +379,7 @@ function main(conf) {
369
379
}
370
380
```
371
381
372
- ## Creating HTTP benchmark
382
+ ### Creating an HTTP benchmark
373
383
374
384
The ` bench ` object returned by ` createBenchmark ` implements
375
385
` http(options, callback) ` method. It can be used to run external tool to
0 commit comments