Prove-It vs Joi

Benchmark created by Dylan on


Description

Prove-it Schema's vs Joi Schema's.

Preparation HTML

<script type="text/javascript" src="https://wzrd.in/standalone/prove-it@0.2.8"></script>
<script type="text/javascript" src="https://wzrd.in/standalone/joi"></script>
<script>
window.prove = proveIt;
window.Joi = joi;
</script>

Setup

var doc = { username: 'abc', birthyear: 1994 };
    
    var proveSchema = prove().object({
        username: prove().string().alphaNumeric().length(3, 30),
        password: prove().string().optional().matches(/[a-zA-Z0-9]{3,30}/),
        access_token: prove().optional().try(prove().string(), prove().number()),
        birthyear: prove().optional().number().integer().min(1900).max(2013),
        email: prove().optional().string().email()
    });
    
    var joiSchema = Joi.object().keys({
        username: Joi.string().alphanum().min(3).max(30).required(),
        password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
        access_token: [Joi.string(), Joi.number()],
        birthyear: Joi.number().integer().min(1900).max(2013),
        email: Joi.string().email()
    });

Test runner

Ready to run.

Testing in
TestOps/sec
Prove Build and Test
var schema = prove().object({
    username: prove().string().alphaNumeric().length(3, 30),
    password: prove().optional().string().matches(/[a-zA-Z0-9]{3,30}/),
    access_token: prove().optional().try(prove().string(), prove().number()),
    birthyear: prove().optional().number().integer().min(1900).max(2013),
    email: prove().optional().string().email()
});

schema.test(doc);
ready
Joi Build and Test
var schema = Joi.object().keys({
    username: Joi.string().alphanum().min(3).max(30).required(),
    password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
    access_token: [Joi.string(), Joi.number()],
    birthyear: Joi.number().integer().min(1900).max(2013),
    email: Joi.string().email()
});

Joi.validate(doc, schema, function (err, value) { });
ready
Prove Test Only
// async test
proveSchema.test(doc);
deferred.resolve();
ready
Joi Test Only
// async test
Joi.validate(doc, joiSchema, function (err, value) {
    deferred.resolve();
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Dylan on