node/benchmark
micnic 8c69d7bed4 domain: forward args to .run(fn)
Adds the feature to define arguments for the function called in
domain.run(), this is supposed to be useful when a function is called from
another context and some values from the current context are needed as
arguments, it's similar to the callback from setTimeout or setInterval.

PR-URL: https://github.com/iojs/io.js/pull/15
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-12 12:14:11 +11:00
..
arrays bench: Consistency in benchmark filenames 2013-02-19 17:16:55 -08:00
buffers bench: fix buffers/buffer-base64-encode benchmark 2014-06-04 14:37:27 -07:00
crypto benchmark: hash stream 2013-05-14 11:36:04 -07:00
fs benchmark: Correct the bufferSize to highWaterMark 2013-11-06 16:32:22 +04:00
http benchmark: update to use new wrk 2014-02-25 11:28:46 -08:00
misc domain: forward args to .run(fn) 2014-12-12 12:14:11 +11:00
net stream_wrap: use `uv_try_write` where possible 2014-01-29 02:49:03 +04:00
tls benchmark: fixate `ciphers` in tls benchmarks 2013-12-07 02:32:03 +04:00
url benchmark: add url benchmarks 2014-12-09 22:16:41 +01:00
README.md doc: Add a README for benchmark tests 2014-05-28 11:58:08 -07:00
common.js benchmark: Fix execArgv handling 2013-08-31 17:58:17 -07:00
compare.js bench: compare binaries equal times 2013-03-20 20:25:48 +01:00
fs-write-stream-throughput.js fs: Change default WriteStream config, increase perf 2013-02-15 18:48:43 -08:00
http-flamegraph.sh benchmark: Make flamegraphs a bit more useful 2012-12-29 15:32:26 -08:00
http.sh benchmark: Set port range properly on Linux 2012-12-29 15:32:26 -08:00
http_bench.js bench: add continuous stress test 2012-04-27 23:11:32 +02:00
http_server_lag.js Typo in http_server_lag.js script 2012-03-06 19:31:16 -08:00
http_simple.js bench: Make http easier to profile 2013-02-25 17:47:28 -08:00
http_simple.rb fix whitespace errors 2010-06-29 23:59:24 -07:00
http_simple_auto.js bench: use res.end() for chunked encoding 2012-12-20 11:44:10 +01:00
http_simple_bench.sh bench: fetch port from env 2012-08-13 18:52:06 +02:00
http_simple_cluster.js bench: start a worker for each CPU 2012-05-25 00:35:10 +02:00
idle_clients.js Add extra anti-DoS tech to net.Server 2010-10-27 12:09:16 -07:00
idle_server.js Abstract out a Server.prototype.pause method 2010-10-28 11:42:22 -07:00
io.c bench: Make io.c output easier to read 2013-02-19 14:14:37 -08:00
plot.R Bump size of bench histogram to 100ms 2011-01-10 18:00:21 -08:00
report-startup-memory.js Add startup memory script to benchmarks 2011-02-18 14:01:04 -08:00
static_http_server.js benchmark: Add resume() in static_http_server 2013-01-17 14:54:59 -08:00

README.md

Node.js core benchmark tests

This folder contains benchmark tests to measure the performance for certain Node.js APIs.

How to run tests

There are two ways to run benchmark tests:

  1. Run all tests of a given type, for example, buffers
node benchmark/common.js buffers

The above command will find all scripts under buffers directory and require each of them as a module. When a test script is required, it creates an instance of Benchmark (a class defined in common.js). In the next tick, the Benchmark constructor iterates through the configuration object property values and run the test function with each of the combined arguments in spawned processes. For example, buffers/buffer-read.js has the following configuration:

var bench = common.createBenchmark(main, {
    noAssert: [false, true],
    buffer: ['fast', 'slow'],
    type: ['UInt8', 'UInt16LE', 'UInt16BE',
        'UInt32LE', 'UInt32BE',
        'Int8', 'Int16LE', 'Int16BE',
        'Int32LE', 'Int32BE',
        'FloatLE', 'FloatBE',
        'DoubleLE', 'DoubleBE'],
        millions: [1]
});

The runner takes one item from each of the property array value to build a list of arguments to run the main function. The main function will receive the conf object as follows:

  • first run:
    {   noAssert: false,
        buffer: 'fast',
        type: 'UInt8',
        millions: 1
    }
  • second run:
    {
        noAssert: false,
        buffer: 'fast',
        type: 'UInt16LE',
        millions: 1
    }

...

In this case, the main function will run 2214*1 = 56 times. The console output looks like the following:

buffers//buffer-read.js
buffers/buffer-read.js noAssert=false buffer=fast type=UInt8 millions=1: 271.83
buffers/buffer-read.js noAssert=false buffer=fast type=UInt16LE millions=1: 239.43
buffers/buffer-read.js noAssert=false buffer=fast type=UInt16BE millions=1: 244.57
...
  1. Run an individual test, for example, buffer-slice.js
node benchmark/buffers/buffer-read.js

The output:

buffers/buffer-read.js noAssert=false buffer=fast type=UInt8 millions=1: 246.79
buffers/buffer-read.js noAssert=false buffer=fast type=UInt16LE millions=1: 240.11
buffers/buffer-read.js noAssert=false buffer=fast type=UInt16BE millions=1: 245.91
...

How to write a benchmark test

The benchmark tests are grouped by types. Each type corresponds to a subdirectory, such as arrays, buffers, or fs.

Let's add a benchmark test for Buffer.slice function. We first create a file buffers/buffer-slice.js.

The code snippet

var common = require('../common.js'); // Load the test runner

var SlowBuffer = require('buffer').SlowBuffer;

// Create a benchmark test for function `main` and the configuration variants
var bench = common.createBenchmark(main, {
  type: ['fast', 'slow'], // Two types of buffer
  n: [512] // Number of times (each unit is 1024) to call the slice API
});

function main(conf) {
  // Read the parameters from the configuration
  var n = +conf.n;
  var b = conf.type === 'fast' ? buf : slowBuf;
  bench.start(); // Start benchmarking
  for (var i = 0; i < n * 1024; i++) {
    // Add your test here
    b.slice(10, 256);
  }
  bench.end(n); // End benchmarking
}