mirror of
https://github.com/Swizec/thaw-carrots.git
synced 2024-09-29 10:45:37 +00:00
Burn CPU in background, keep measuring temp
This commit is contained in:
parent
30d20527c5
commit
dc1c106671
12
eat-cpu.js
Normal file
12
eat-cpu.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Borrowed from https://gist.github.com/sqren/5083d73f184acae0c5b7
|
||||||
|
|
||||||
|
function mySlowFunction(baseNumber) {
|
||||||
|
var result = 0;
|
||||||
|
for (var i = Math.pow(baseNumber, 10); i >= 0; i--) {
|
||||||
|
result += Math.atan(i) * Math.tan(i);
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// module.exports = mySlowFunction;
|
||||||
|
mySlowFunction(8);
|
16
index.js
16
index.js
|
@ -2,8 +2,7 @@ const si = require("systeminformation");
|
||||||
const mri = require("mri");
|
const mri = require("mri");
|
||||||
const sll = require("single-line-log").stdout;
|
const sll = require("single-line-log").stdout;
|
||||||
const kleur = require("kleur");
|
const kleur = require("kleur");
|
||||||
const isPrime = require("prime-number");
|
const fork = require("child_process").fork;
|
||||||
const eatCPU = require("./eat-cpu");
|
|
||||||
|
|
||||||
async function readTemp() {
|
async function readTemp() {
|
||||||
const temp = await si.cpuTemperature();
|
const temp = await si.cpuTemperature();
|
||||||
|
@ -12,12 +11,17 @@ async function readTemp() {
|
||||||
|
|
||||||
async function thawMyCarrots(targetTemp) {
|
async function thawMyCarrots(targetTemp) {
|
||||||
let temp = await readTemp(),
|
let temp = await readTemp(),
|
||||||
n = 2;
|
children = [];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (temp.main < targetTemp) {
|
if (temp.main < targetTemp) {
|
||||||
eatCPU(n);
|
if (children.length < 10) {
|
||||||
n = n + 1;
|
children.push(fork("./eat-cpu"));
|
||||||
|
}
|
||||||
|
} else if (temp.main > targetTemp) {
|
||||||
|
if (children.length > 0) {
|
||||||
|
children.pop().kill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
temp = await readTemp();
|
temp = await readTemp();
|
||||||
|
@ -26,7 +30,7 @@ async function thawMyCarrots(targetTemp) {
|
||||||
kleur.bold.red(temp.main.toFixed(2)),
|
kleur.bold.red(temp.main.toFixed(2)),
|
||||||
"\nCores at",
|
"\nCores at",
|
||||||
kleur.bold.gray(temp.cores),
|
kleur.bold.gray(temp.cores),
|
||||||
n
|
`\nChildren: ${children.length}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue