Skip to content

Commit

Permalink
Split bench.js to runner and benchmark function.
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkasm committed Dec 25, 2016
1 parent 89fef1f commit e274907
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
22 changes: 5 additions & 17 deletions bench/bench.js → bench/benchStylesheet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import Benchmark from 'benchmark'

import Stylesheet from '../src/stylesheet'
import Node from '../src/node'

Expand Down Expand Up @@ -91,21 +89,11 @@ const elemNode = new Node('Elem', {}, appViewNode, s)
const itemNode = new Node('Item', {}, elemNode, s)
const textNode = new Node('Text', {prop1: 1}, itemNode, s)

const suite = new Benchmark.Suite()
let props
suite.add('new theme & props', function () {
props = s.getProps(textNode)
function benchStylesheet () {
const props = s.getProps(textNode)
if (props.style.fontSize !== 12) {
throw new Error('fontSize != 12')
}
})
suite.on('cycle', function (e) {
console.log(String(e.target))
if (e.target.error) {
console.log('Error: ', e.target.error)
}
})
suite.on('complete', function () {
console.log('Done')
})
suite.run()
}

export default benchStylesheet
19 changes: 19 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import Benchmark from 'benchmark'

import benchStylesheet from './benchStylesheet'

const suite = new Benchmark.Suite()

suite.add('Stylesheet#getProps', benchStylesheet)

suite.on('cycle', function (e) {
console.log(String(e.target))
if (e.target.error) {
console.log('Error: ', e.target.error)
}
})
suite.on('complete', function () {
console.log('Done')
})
suite.run()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.js",
"scripts": {
"test": "mocha -r test/setup test/*.spec.js",
"bench": "node -r babel-register bench/bench.js",
"bench": "node -r babel-register bench/index.js",
"cover": "cross-env ISTANBUL_COVERAGE=yes nyc mocha -r test/setup test/*.spec.js"
},
"nyc": {
Expand Down

0 comments on commit e274907

Please sign in to comment.