• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4// This benchmark uses `yes` to a create noisy child_processes with varying
5// output message lengths, and tries to read 8GB of output
6
7const os = require('os');
8const child_process = require('child_process');
9
10const messagesLength = [64, 256, 1024, 4096];
11// Windows does not support that long arguments
12if (os.platform() !== 'win32')
13  messagesLength.push(32768);
14
15const bench = common.createBenchmark(main, {
16  len: messagesLength,
17  dur: [5]
18});
19
20function main({ dur, len }) {
21  bench.start();
22
23  const msg = `"${'.'.repeat(len)}"`;
24  const options = { 'stdio': ['ignore', 'pipe', 'ignore'] };
25  const child = child_process.spawn('yes', [msg], options);
26
27  let bytes = 0;
28  child.stdout.on('data', (msg) => {
29    bytes += msg.length;
30  });
31
32  setTimeout(() => {
33    if (process.platform === 'win32') {
34      // Sometimes there's a yes.exe process left hanging around on Windows...
35      child_process.execSync(`taskkill /f /t /pid ${child.pid}`);
36    } else {
37      child.kill();
38    }
39    const gbits = (bytes * 8) / (1024 * 1024 * 1024);
40    bench.end(gbits);
41  }, dur * 1000);
42}
43