Skip to content

Instantly share code, notes, and snippets.

@new-guy
Created August 17, 2015 21:45
Show Gist options
  • Save new-guy/942384ca67fc646ae017 to your computer and use it in GitHub Desktop.
Save new-guy/942384ca67fc646ae017 to your computer and use it in GitHub Desktop.
////////////SETTINGS/////////////
var LOG_AVERAGE_CPU = false;
/////////////////////////////////
module.exports = function(){
initMemory();
if(LOG_AVERAGE_CPU)
{
logAverageCpu();
}
};
function initMemory()
{
if(Memory.utils === undefined)
{
Memory.utils = {};
}
}
function logAverageCpu()
{
if(Memory.utils.usedCpuHistory === undefined)
{
Memory.utils.usedCpuHistory = [];
}
var currentCpu = Game.getUsedCpu();
Memory.usedCpuHistory.unshift(currentCpu);
if(Memory.usedCpuHistory.length > 50)
{
Memory.usedCpuHistory.pop();
}
var totalCpu = 0;
for(var i = 0; i < Memory.usedCpuHistory.length; i++)
{
totalCpu += parseInt(Memory.usedCpuHistory);
}
var averageCpu = totalCpu/Memory.usedCpuHistory.length;
console.log(totalCpu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment