Skip to content

Instantly share code, notes, and snippets.

@bonzaiferroni
Created June 2, 2017 21:38
Show Gist options
  • Save bonzaiferroni/5fe6aba134f1ed35cefa305b31cfb20b to your computer and use it in GitHub Desktop.
Save bonzaiferroni/5fe6aba134f1ed35cefa305b31cfb20b to your computer and use it in GitHub Desktop.
Tests for memory overhead with different traveler objects
testCPU() {
let obj1 = {
_trav: {
stuck: 0,
cpu: 133,
last: { x: 17, y: 29 },
dest: { x: 18, y: 31, roomName: "E22S24" },
path: "42640344898844894894",
},
};
let obj2 = {
_trav: {
state: [17, 29, 0, 133, 18, 31, "E22S24"],
path: "42640344898844894894",
},
};
// this object would require further parsing to use
let obj3 = {
_trav: {
state: "17_29_0_133_18_31_E22S24",
path: "42640344898844894894",
},
};
let testObjects = [obj1, obj2, obj3];
let testNumber = 1;
for (let testObj of testObjects) {
let fakeMemory = {
creeps: {},
};
for (let creepName in Game.creeps) {
fakeMemory.creeps[creepName] = testObj;
}
let cpu = Game.cpu.getUsed();
let str = JSON.stringify(fakeMemory);
JSON.parse(str);
cpu = Game.cpu.getUsed() - cpu;
console.log(`test: ${testNumber}, creepCount: ${Object.keys(fakeMemory.creeps).length}, result: ${cpu}`);
testNumber++;
}
},
/* output
test: 1, creepCount: 745, result: 2.6276000000000295
test: 2, creepCount: 745, result: 1.445475999999985
test: 3, creepCount: 745, result: 1.248032999999964
test: 1, creepCount: 744, result: 2.174299999999988
test: 2, creepCount: 744, result: 1.2194879999999841
test: 3, creepCount: 744, result: 0.9736540000000105
test: 1, creepCount: 744, result: 2.0394410000000107
test: 2, creepCount: 744, result: 1.1468979999999647
test: 3, creepCount: 744, result: 0.9529650000000061
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment