Sha256: 21da2d4d47bda6690e370b86f4b8b58cf531587e622599bdc521079d9bb23957

Contents?: true

Size: 961 Bytes

Versions: 5

Compression:

Stored size: 961 Bytes

Contents

'use strict';
require('../common');
const assert = require('assert');

const start = process.cpuUsage();

// Run a busy-loop for specified # of milliseconds.
const RUN_FOR_MS = 500;

// Define slop factor for checking maximum expected diff values.
const SLOP_FACTOR = 2;

// Run a busy loop.
const now = Date.now();
while (Date.now() - now < RUN_FOR_MS);

// Get a diff reading from when we started.
const diff = process.cpuUsage(start);

const MICROSECONDS_PER_SECOND = 1000 * 1000;

// Diff usages should be >= 0, <= ~RUN_FOR_MS millis.
// Let's be generous with the slop factor, defined above, in case other things
// are happening on this CPU. The <= check may be invalid if the node process
// is making use of multiple CPUs, in which case, just remove it.
assert(diff.user >= 0);
assert(diff.user <= SLOP_FACTOR * RUN_FOR_MS * MICROSECONDS_PER_SECOND);

assert(diff.system >= 0);
assert(diff.system <= SLOP_FACTOR * RUN_FOR_MS * MICROSECONDS_PER_SECOND);

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/pummel/test-process-cpuUsage.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/pummel/test-process-cpuUsage.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/pummel/test-process-cpuUsage.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/pummel/test-process-cpuUsage.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/pummel/test-process-cpuUsage.js