From 633b0c5a49d47e3aae76670f333a14e5c1884d65 Mon Sep 17 00:00:00 2001 From: Guntars Asmanis-Graham Date: Fri, 8 Jul 2016 13:59:02 -0400 Subject: [PATCH] Add a benchmark for changes in #490 --- bench.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 bench.js diff --git a/bench.js b/bench.js new file mode 100644 index 000000000..bed1c33d6 --- /dev/null +++ b/bench.js @@ -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 }) diff --git a/package.json b/package.json index 2ab41653d..36a8f62c6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -51,6 +52,7 @@ "author": "Leland Richardson ", "license": "MIT", "dependencies": { + "benchmark": "^2.1.0", "cheerio": "^0.20.0", "is-subset": "^0.1.1", "lodash": "^4.13.1",