-
-
Save endel/72e4a3e219e2ff4ed21240d50621668b to your computer and use it in GitHub Desktop.
This file contains 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
import { toJSON } from "../../src/Utils"; | |
const suite = new Benchmark.Suite(); | |
const NUM_CLIENTS = 2; | |
const NUM_MONSTERS = 500; | |
const MAP_GRID_SIZE = 200; | |
// build 200x200 map | |
const map = []; | |
for (var i=0; i<MAP_GRID_SIZE; i++) { | |
map[i] = []; | |
for (var j=0; j<MAP_GRID_SIZE; j++) { | |
map[i].push( (Math.random() > 0.5) ? 0 : 1 ); | |
} | |
} | |
// build 500 monsters | |
let monsters = {}; | |
for (let i=0; i<NUM_MONSTERS; i++) { | |
monsters[ generateId() ] = { | |
x: Math.round(Math.random() * 200), | |
y: Math.round(Math.random() * 200) | |
}; | |
} | |
// build 10 players | |
let players = {}; | |
for (let i=0; i<NUM_CLIENTS; i++) { | |
players[ generateId() ] = { | |
x: Math.round(Math.random() * 200), | |
y: Math.round(Math.random() * 200) | |
}; | |
} | |
function moveMonsters () { | |
for (let id in monsters) { | |
monsters[ id ].x += (Math.random() > 0.5) ? 1 : -1; | |
monsters[ id ].y += (Math.random() > 0.5) ? 1 : -1; | |
} | |
} | |
function movePlayers () { | |
for (let id in players) { | |
players[ id ].x += (Math.random() > 0.5) ? 1 : -1; | |
players[ id ].y += (Math.random() > 0.5) ? 1 : -1; | |
} | |
} | |
let state = { map, monsters, players }; | |
suite.add('toJSON', () => toJSON(state)); | |
suite.on('cycle', e => console.log( e.target.toString() )); | |
suite.run(); | |
console.log("Done.") | |
process.exit(); |
This file contains 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
toJSON x 13.63 ops/sec ±6.76% (35 runs sampled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment