1- # Node.js core benchmark
1+ # How to Write and Run Benchmarks in Node.js Core
22
3- This folder contains benchmarks to measure the performance of the Node.js APIs.
4-
5- ## Table of Content
3+ ## Table of Contents
64
75* [ Prerequisites] ( #prerequisites )
6+ * [ HTTP Benchmark Requirements] ( #http-benchmark-requirements )
7+ * [ Benchmark Analysis Requirements] ( #benchmark-analysis-requirements )
88* [ 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 )
1313* [ Creating a benchmark] ( #creating-a-benchmark )
14+ * [ Basics of a benchmark] ( #basics-of-a-benchmark )
15+ * [ Creating an HTTP benchmark] ( #creating-an-http-benchmark )
1416
1517## Prerequisites
1618
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+
1725Most of the HTTP benchmarks require a benchmarker to be installed, this can be
1826either [ ` wrk ` ] [ wrk ] or [ ` autocannon ` ] [ autocannon ] .
1927
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
2230path, 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.
2432
2533` wrk ` may be available through your preferred package manager. If not, you can
2634easily build it [ from source] [ wrk ] via ` make ` .
@@ -34,9 +42,7 @@ benchmarker to be used by providing it as an argument, e. g.:
3442
3543` node benchmark/http/simple.js benchmarker=autocannon `
3644
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
4046
4147To analyze the results ` R ` should be installed. Check you package manager or
4248download it from https://www.r-project.org/ .
@@ -50,7 +56,6 @@ install.packages("ggplot2")
5056install.packages(" plyr" )
5157```
5258
53- ### CRAN Mirror Issues
5459In the event you get a message that you need to select a CRAN mirror first.
5560
5661You 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
108113### Running all benchmarks
109114
110115Similar 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
112118information to make any conclusions.
113119
114120``` console
@@ -135,18 +141,19 @@ It is possible to execute more groups by adding extra process arguments.
135141$ node benchmark/run.js arrays buffers
136142```
137143
138- ### Comparing node versions
144+ ### Comparing Node.js versions
139145
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
141147will 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 ` .
143150
144151As an example on how to check for a possible performance improvement, the
145152[ #5134 ] ( https://github.com/nodejs/node/pull/5134 ) pull request will be used as
146153an example. This pull request _ claims_ to improve the performance of the
147154` string_decoder ` module.
148155
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
150157` ./node-master ` ) and another with the pull request applied (here called
151158` ./node-pr-5135 ` ).
152159
@@ -219,7 +226,8 @@ It can be useful to compare the performance for different parameters, for
219226example to analyze the time complexity.
220227
221228To 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 ` .
223231
224232``` console
225233$ node benchmark/scatter.js benchmark/string_decoder/string-decoder.js > scatter.csv
@@ -286,6 +294,8 @@ chunk encoding mean confidence.interval
286294
287295## Creating a benchmark
288296
297+ ### Basics of a benchmark
298+
289299All benchmarks use the ` require('../common.js') ` module. This contains the
290300` createBenchmark(main, configs[, options]) ` method which will setup your
291301benchmark.
@@ -369,7 +379,7 @@ function main(conf) {
369379}
370380```
371381
372- ## Creating HTTP benchmark
382+ ### Creating an HTTP benchmark
373383
374384The ` bench ` object returned by ` createBenchmark ` implements
375385` http(options, callback) ` method. It can be used to run external tool to
0 commit comments