Skip to content

Commit

Permalink
add basic perf
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Dec 14, 2017
1 parent 37c74a5 commit 00b5b4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"prettier --no-semi --single-quote --print-width 120 --parser flow --write \"{src,test,examples,exercises}/**/*.js.flow\"",
"test": "npm run prettier && npm run lint && npm run typings-checker && npm run mocha",
"clean": "rm -rf lib/*",
"build": "npm run clean && tsc && npm run flow-copy-definition-files"
"build": "npm run clean && tsc && npm run flow-copy-definition-files",
"perf": "node perf/index"
},
"repository": {
"type": "git",
Expand All @@ -38,6 +39,7 @@
"devDependencies": {
"@types/mocha": "2.2.38",
"@types/node": "7.0.4",
"benchmark": "2.1.4",
"mocha": "3.2.0",
"prettier": "1.8.2",
"ts-node": "3.2.0",
Expand Down
28 changes: 28 additions & 0 deletions perf/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var Benchmark = require('benchmark')
var t = require('../lib/index')

const suite = new Benchmark.Suite()

const T = t.type({
a: t.string,
b: t.number,
c: t.array(t.boolean),
d: t.tuple([t.number, t.string])
})
const payloadKO = { c: [1], d: ['foo'] }
const payloadOK = { a: 'a', b: 1, c: [true], d: [1, 'foo'] }

suite
.add('invalid payload', function() {
t.validate(payloadKO, T)
})
.add('valid payload (no errors)', function() {
t.validate(payloadOK, T)
})
.on('cycle', function(event) {
console.log(String(event.target))
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ async: true })

0 comments on commit 00b5b4e

Please sign in to comment.