mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
227ca87abb
This commit adds a test to validate if Linux perf is working correctly on Node.js. The test is marked as flaky because its intention is to let us know when changes on V8 potentially broke Linux perf, so we can fix it before a new version of V8 lands on Node.js master. PR-URL: https://github.com/nodejs/node/pull/20783 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
27 lines
820 B
JavaScript
27 lines
820 B
JavaScript
'use strict';
|
|
|
|
const crypto = require('crypto');
|
|
|
|
// Functions should be complex enough for V8 to run them a few times before
|
|
// compiling, but not complex enough to always stay in interpreted mode. They
|
|
// should also take some time to run, otherwise Linux perf might miss them
|
|
// entirely even when sampling at a high frequency.
|
|
function functionOne(i) {
|
|
for (let j=i; j > 0; j--) {
|
|
crypto.createHash('md5').update(functionTwo(i, j)).digest("hex");
|
|
}
|
|
}
|
|
|
|
function functionTwo(x, y) {
|
|
let data = ((((x * y) + (x / y)) * y) ** (x + 1)).toString();
|
|
if (x % 2 == 0) {
|
|
return crypto.createHash('md5').update(data.repeat((x % 100) + 1)).digest("hex");
|
|
} else {
|
|
return crypto.createHash('md5').update(data.repeat((y % 100) + 1)).digest("hex");
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < 1000; i++) {
|
|
functionOne(i);
|
|
}
|