Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Jul 25, 2019
1 parent 7fc8979 commit 221b0d5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
39 changes: 39 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2019 The boardgame.io Authors
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

import Benchmark from 'benchmark';
import Game from '../src/core/game';
import { InitializeGame, CreateGameReducer } from '../src/core/reducer';
import { makeMove, gameEvent } from '../src/core/action-creators';

const game = Game({
moves: {
A: G => G,
},
flow: {
endGameIf: (G, ctx) => (G.victory ? ctx.currentPlayer : undefined),
},
});

const reducer = CreateGameReducer({ game });
const state = InitializeGame({ game });

new Benchmark.Suite()
.add('move', function() {
reducer(state, makeMove('A'));
})
.add('endTurn', function() {
reducer(state, gameEvent('endTurn'));
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev:client": "(cd examples/react-web; npm start)",
"dev:server": "cross-env NODE_ENV=development nodemon -w src -w examples -e js,ts --exec babel-node --extensions '.ts,.js' --ignore 'src/**/*.test.ts' --presets @babel/preset-env examples/react-web/server.js",
"build": "cross-env BABEL_ENV=rollup rollup --config rollup.npm.js",
"benchmark": "babel-node --presets @babel/preset-env benchmark/index.js",
"docsify": "docsify serve docs",
"docsify:update": "npm run build && node ./scripts/docsify-update.js",
"examples": "npm run start",
Expand All @@ -21,7 +22,7 @@
"lint:fix": "eslint --fix .",
"prepack": "npm run build && generate-export-aliases",
"postpack": "npm run clean",
"prettier": "prettier --write \"{examples,src}/**/*.{js,css,md}\"",
"prettier": "prettier --write \"{examples,src,benchmark}/**/*.{js,css,md}\"",
"changelog": "bash ./scripts/changelog.sh",
"clean": "node ./scripts/clean.js"
},
Expand Down Expand Up @@ -81,6 +82,7 @@
"babel-eslint": "^8.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-module-resolver": "^3.0.0",
"benchmark": "^2.1.4",
"concurrently": "^4.1.0",
"coveralls": "^3.0.0",
"cross-env": "^5.1.1",
Expand Down

0 comments on commit 221b0d5

Please sign in to comment.