Created
June 5, 2017 19:05
-
-
Save bonzaiferroni/b4d7736f8563848da57776146e60b9ef to your computer and use it in GitHub Desktop.
testing "overhead" of managing state objects with function call vs. without
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testCPU() { | |
const STATE_PREV_X = 0; | |
const STATE_PREV_Y = 1; | |
const STATE_STUCK = 2; | |
const STATE_CPU = 3; | |
const STATE_DEST_X = 4; | |
const STATE_DEST_Y = 5; | |
const STATE_DEST_ROOMNAME = 6; | |
let creep = Game.creeps["newTraveler"]; | |
let travelData = creep.memory._trav; | |
let destination = Game.flags["travFlag"].pos; | |
let withoutFunctionCall = () => { | |
// let state = this.deserializeState(travelData, destination); | |
let state = {} as TravelState; | |
if (travelData.state) { | |
state.lastCoord = {x: travelData.state[STATE_PREV_X], y: travelData.state[STATE_PREV_Y] }; | |
state.cpu = travelData.state[STATE_CPU]; | |
state.stuckCount = travelData.state[STATE_STUCK]; | |
state.destination = new RoomPosition(travelData.state[STATE_DEST_X], travelData.state[STATE_DEST_Y], | |
travelData.state[STATE_DEST_ROOMNAME]); | |
} else { | |
state.cpu = 0; | |
state.destination = destination; | |
} | |
// this.serializeState(creep, destination, state, travelData); | |
travelData.state = [creep.pos.x, creep.pos.y, state.stuckCount, state.cpu, destination.x, destination.y, | |
destination.roomName]; | |
}; | |
let withFunctionCall = () => { | |
let state = Traveler.deserializeState(travelData, destination); | |
Traveler.serializeState(creep, destination, state, travelData); | |
}; | |
let tests = [withFunctionCall, withoutFunctionCall]; | |
for (let test of tests) { | |
let cpu = Game.cpu.getUsed(); | |
for (let i = 0; i < 100; i++) { | |
test(); | |
} | |
console.log(`test: ${test.name}, cpu: ${Game.cpu.getUsed() - cpu}`); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment