xref: /third_party/node/benchmark/README.md (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci# Node.js Core Benchmarks
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciThis folder contains code and data used to measure performance
41cb0ef41Sopenharmony_ciof different Node.js implementations and different ways of
51cb0ef41Sopenharmony_ciwriting JavaScript run by the built-in JavaScript engine.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciFor a detailed guide on how to write and run benchmarks in this
81cb0ef41Sopenharmony_cidirectory, see [the guide on benchmarks](../doc/contributing/writing-and-running-benchmarks.md).
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci## Table of Contents
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci* [File tree structure](#file-tree-structure)
131cb0ef41Sopenharmony_ci* [Common API](#common-api)
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci## File tree structure
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci### Directories
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciBenchmarks testing the performance of a single node submodule are placed into a
201cb0ef41Sopenharmony_cidirectory with the corresponding name, so that they can be executed by submodule
211cb0ef41Sopenharmony_cior individually.
221cb0ef41Sopenharmony_ciBenchmarks that span multiple submodules may either be placed into the `misc`
231cb0ef41Sopenharmony_cidirectory or into a directory named after the feature they benchmark.
241cb0ef41Sopenharmony_ciE.g. benchmarks for various new ECMAScript features and their pre-ES2015
251cb0ef41Sopenharmony_cicounterparts are placed in a directory named `es`.
261cb0ef41Sopenharmony_ciFixtures that are not specific to a certain benchmark but can be reused
271cb0ef41Sopenharmony_cithroughout the benchmark suite should be placed in the `fixtures` directory.
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci### Other Top-level files
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciThe top-level files include common dependencies of the benchmarks
321cb0ef41Sopenharmony_ciand the tools for launching benchmarks and visualizing their output.
331cb0ef41Sopenharmony_ciThe actual benchmark scripts should be placed in their corresponding
341cb0ef41Sopenharmony_cidirectories.
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci* `_benchmark_progress.js`: implements the progress bar displayed
371cb0ef41Sopenharmony_ci  when running `compare.js`
381cb0ef41Sopenharmony_ci* `_cli.js`: parses the command line arguments passed to `compare.js`,
391cb0ef41Sopenharmony_ci  `run.js` and `scatter.js`
401cb0ef41Sopenharmony_ci* `_cli.R`: parses the command line arguments passed to `compare.R`
411cb0ef41Sopenharmony_ci* `_http-benchmarkers.js`: selects and runs external tools for benchmarking
421cb0ef41Sopenharmony_ci  the `http` subsystem.
431cb0ef41Sopenharmony_ci* `common.js`: see [Common API](#common-api).
441cb0ef41Sopenharmony_ci* `compare.js`: command line tool for comparing performance between different
451cb0ef41Sopenharmony_ci  Node.js binaries.
461cb0ef41Sopenharmony_ci* `compare.R`: R script for statistically analyzing the output of
471cb0ef41Sopenharmony_ci  `compare.js`
481cb0ef41Sopenharmony_ci* `run.js`: command line tool for running individual benchmark suite(s).
491cb0ef41Sopenharmony_ci* `scatter.js`: command line tool for comparing the performance
501cb0ef41Sopenharmony_ci  between different parameters in benchmark configurations,
511cb0ef41Sopenharmony_ci  for example to analyze the time complexity.
521cb0ef41Sopenharmony_ci* `scatter.R`: R script for visualizing the output of `scatter.js` with
531cb0ef41Sopenharmony_ci  scatter plots.
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci## Common API
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ciThe common.js module is used by benchmarks for consistency across repeated
581cb0ef41Sopenharmony_citasks. It has a number of helpful functions and properties to help with
591cb0ef41Sopenharmony_ciwriting benchmarks.
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci### `createBenchmark(fn, configs[, options])`
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciSee [the guide on writing benchmarks](../doc/contributing/writing-and-running-benchmarks.md#basics-of-a-benchmark).
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci### `default_http_benchmarker`
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciThe default benchmarker used to run HTTP benchmarks.
681cb0ef41Sopenharmony_ciSee [the guide on writing HTTP benchmarks](../doc/contributing/writing-and-running-benchmarks.md#creating-an-http-benchmark).
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci### `PORT`
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ciThe default port used to run HTTP benchmarks.
731cb0ef41Sopenharmony_ciSee [the guide on writing HTTP benchmarks](../doc/contributing/writing-and-running-benchmarks.md#creating-an-http-benchmark).
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci### `sendResult(data)`
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciUsed in special benchmarks that can't use `createBenchmark` and the object
781cb0ef41Sopenharmony_ciit returns to accomplish what they need. This function reports timing
791cb0ef41Sopenharmony_cidata to the parent process (usually created by running `compare.js`, `run.js` or
801cb0ef41Sopenharmony_ci`scatter.js`).
81