Last active
March 3, 2016 18:00
-
-
Save fortruce/7d9cd8b52cddde64b6b7 to your computer and use it in GitHub Desktop.
Perf test of Joi vs PropTypes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Joi = require("joi"); | |
const PropTypes = require("./src/proptypes"); | |
const checkPropTypes = require("./src/proptypes/check-prop-types"); | |
const range = Array.from({length: 40}).map((_, index) => index); | |
const schemaObj = range.reduce((schema, i) => { | |
schema[i] = Joi.string().required(); | |
return schema; | |
}, {}); | |
const propTypes = range.reduce((types, i) => { | |
types[i] = PropTypes.string.isRequired; | |
return types; | |
}, {}); | |
const obj = range.reduce((obj, i) => { | |
obj[i] = "abcdef12345"; | |
return obj; | |
}, {}); | |
const schema = Joi.object().keys(schemaObj); | |
const schemaArr = Joi.object().keys({ | |
elements: Joi.array().items(schema) | |
}); | |
const propTypesArr = { | |
elements: PropTypes.arrayOf(PropTypes.shape(propTypes)) | |
}; | |
const arr = Array.from({length: 1500}).fill(obj); | |
const before = Date.now(); | |
const result = checkPropTypes("testArr", propTypesArr, {elements: arr}); | |
// const result = Joi.validate({elements: arr}, schemaArr); | |
const after = Date.now(); | |
console.log(`DONE: ${after - before}ms`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment