High CPU usage differences on a tiny script
-
module.exports.loop = function () { console.log("Tick: "); var CPU_LIMIT = Game.cpuLimit; console.log(Game.getUsedCpu()+"/"+CPU_LIMIT); for(var i in Memory.creeps) { if(!Game.creeps[i]) { delete Memory.creeps[i]; } } console.log(Game.getUsedCpu()+"/"+CPU_LIMIT); }
This produces huge differences in cpu time used from ~1 to ~20.
Also the cpu usage is already very high at the first log already...Is this normal behaviour?
-
Delete is a fairly expensive operation, but I think the spikes are probably from require statements. Currently there doesn't seem to be a way around this, as in-lining all the code also makes the CPU spike.
The only solace is that when using `module.exports.loop` your require statements aren't always run.