Last active
November 8, 2020 16:06
-
-
Save yaliv/0f1f0efaddbccf70acc70ad9f0826848 to your computer and use it in GitHub Desktop.
Benchmark gojsonschema validation in parallel
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
package jscvalidator | |
import ( | |
"testing" | |
"github.com/xeipuuv/gojsonschema" | |
) | |
const ( | |
passwordSchema = `{ | |
"type": "object", | |
"required": ["oldPassword", "newPassword"], | |
"properties": { | |
"oldPassword": { | |
"type": "string", | |
"minLength": 1 | |
}, | |
"newPassword": { | |
"type": "string", | |
"minLength": 1 | |
} | |
} | |
}` | |
changePasswordBody = `{ | |
"oldPassword": "12QWaszx", | |
"newPassword": "omkopi" | |
}` | |
) | |
func BenchmarkValidate(b *testing.B) { | |
schema, _ := gojsonschema.NewSchema(gojsonschema.NewStringLoader(passwordSchema)) | |
b.RunParallel(func(pb *testing.PB) { | |
for pb.Next() { | |
schema.Validate(gojsonschema.NewStringLoader(changePasswordBody)) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment