Skip to content

Commit

Permalink
Add a benchmark for changes in enzymejs#490
Browse files Browse the repository at this point in the history
  • Loading branch information
guncha committed Jul 8, 2016
1 parent 78f22ee commit 633b0c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var Benchmark = require("benchmark")
var Enzyme = require(".")
var React = require("react")

var Component = React.createClass({
render() {
return React.createElement("section", null, React.createElement("h1", null), React.createElement("div", null, React.createElement("p", null, "The daily random number is: ", React.createElement("span", { className: "random" }, Math.random()))))
}
})

var wrapper = Enzyme.shallow(React.createElement(Component, null))

function update(wrapper) {
wrapper.node = wrapper.renderer.getRenderOutput()
wrapper.nodes = [wrapper.node]
}

console.log()
console.log(wrapper.text())
wrapper.instance().setState({hello: 123})
console.log(wrapper.text()) // <- Should update with the new changes
console.log()

new Benchmark.Suite()
.add(".find('span')", function () {
wrapper.find("span")
})
.add(".find('span') with update", function () {
update(wrapper)
wrapper.find("span")
})
.on("cycle", function (event) {
console.log(String(event.target))
})
.run({ async: true })
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"version": "npm run build",
"clean": "rimraf build",
"lint": "eslint src/** test/**",
"bench": "npm run build && node ./bench.js",
"check": "npm run lint && npm run test:all",
"build": "babel src --out-dir build",
"test": "npm run test:only",
Expand Down Expand Up @@ -51,6 +52,7 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"benchmark": "^2.1.0",
"cheerio": "^0.20.0",
"is-subset": "^0.1.1",
"lodash": "^4.13.1",
Expand Down

0 comments on commit 633b0c5

Please sign in to comment.