-
Notifications
You must be signed in to change notification settings - Fork 2
feat: benchmark tests between validgen and validator #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces comprehensive benchmarking infrastructure to compare ValidGen performance against the go-playground/validator library. The implementation includes automated test generation, Makefile integration, and detailed performance documentation showing ValidGen's significant speed advantages across various validation scenarios.
Key changes include:
- Automated benchmark test generation using Go templates to create comparable test cases for both ValidGen and validator libraries
- Enhanced Makefile with new
cmpbenchteststarget for streamlined benchmark execution and cleanup - Performance documentation with detailed benchmark results demonstrating ValidGen's 8-10x performance improvements
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tests/cmpbenchtests/generate_cmp_benchtests_main.go |
Main generator program that creates benchmark test files from templates |
tests/cmpbenchtests/*.tpl |
Template files for generating type definitions and benchmark test functions |
tests/cmpbenchtests/generated_tests/* |
Auto-generated benchmark tests and ValidGen validator functions |
tests/bench/types.go |
Centralized struct definitions moved from individual test files |
Makefile |
Enhanced with cmpbenchtests target and improved build variables |
README.md |
Added comprehensive benchmark documentation with performance comparison table |
| ValidInput: "aaa@example.com", | ||
| }, | ||
|
|
||
| // nin |
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment '// nin' appears to be incomplete or unclear. It should either be removed or expanded to explain what 'nin' refers to (possibly 'not in' validation).
| // nin | |
| { | |
| TestType: "StringNotIn", | |
| FieldType: "string", | |
| ValidGenValidate: "not_in=ab cd ef", | |
| ValidatorValidate: "not_oneof=ab cd ef", | |
| ValidInput: "gh", | |
| }, |
| package benchtests | ||
|
|
||
| type StructValidGen struct { | ||
| FirstName string `valid:"required"` |
Copilot
AI
Jul 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The struct uses valid tags but the previous version used verify tags. According to ValidGen guidelines, the tag should be valid for compatibility with go-playground/validator syntax.
Closes #26
This PR introduces significant enhancements to the benchmarking infrastructure for the
ValidGenproject, including the addition of new benchmark tests, improved Makefile commands, and the generation of validation code. The changes aim to streamline benchmarking, improve maintainability, and provide a clear comparison betweenValidGenand theValidatorproject.Benchmarking Enhancements:
New
cmpbenchtestsTarget inMakefile: Added acmpbenchteststarget to automate the process of generating, building, and running benchmark tests comparingValidGenandValidator. It includes dynamic test file generation and uses a configurable benchmark duration (BENCH_TIME). ([MakefileR1-R38](https://github.com/opencodeco/validgen/pull/35/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R1-R38))Benchmark Test Results in
README.md: Documented steps to run the new benchmark tests and included a detailed comparison table of the results, showcasingValidGen's performance advantages. ([README.mdR161-R213](https://github.com/opencodeco/validgen/pull/35/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R161-R213))Code Generation for Benchmarking:
Test File Generation Logic: Introduced a new Go program (
tests/cmpbenchtests/generate_cmp_benchtests_main.go) to dynamically generate benchmark test files using templates. This program creates type definitions and benchmark functions for various validation scenarios. ([tests/cmpbenchtests/generate_cmp_benchtests_main.goR1-R133](https://github.com/opencodeco/validgen/pull/35/files#diff-e3eaec9ac1185ae884e52bc1f0e30547ee03c30422439ee9e0cf01274f43283cR1-R133))Generated Benchmark Test Files: Added auto-generated files for benchmark tests (
validgen_vs_validator_test.go) and struct definitions (types.go) to compareValidGenandValidatorperformance across multiple validation cases. ([[1]](https://github.com/opencodeco/validgen/pull/35/files#diff-956a9f1a8573ecb6c4f5668ff05770644124d846f0a25e6f5f8df38803da9982R1-R83),[[2]](https://github.com/opencodeco/validgen/pull/35/files#diff-d859401c1013babe45a1fc3d218f44294caa9948f87f891b97aa17315808f92fR1-R279))Validation Code Improvements:
ValidGento handle specific validation scenarios (e.g.,required,eq,neq, etc.). These files are generated byValidGenand should not be manually edited. ([[1]](https://github.com/opencodeco/validgen/pull/35/files#diff-f4a0eb6dea03798c3585b934ac4ec4e95ad8431e1d2ed8c4cf3d4aadcef58bf2R1-R17),[[2]](https://github.com/opencodeco/validgen/pull/35/files#diff-842b5dd0fcb764de4ca74fa01f2f944749fa9dacb5f86580697a75e8ab898ef9R1-R17),[[3]](https://github.com/opencodeco/validgen/pull/35/files#diff-83130de5a9ca106b8f831a05b2969b470b44412184dd3fad28e5e21a6580f0a5R1-R17),[[4]](https://github.com/opencodeco/validgen/pull/35/files#diff-e1d6b8a32ffb11513ed0d7bd1d8528d781e957ec0469fd899809baeefcf31a10R1-R17),[[5]](https://github.com/opencodeco/validgen/pull/35/files#diff-1a060791e49f4bb135793206d58fc7f37f8737aaaef1b8744a400e7b06d9bd83R1-R17),[[6]](https://github.com/opencodeco/validgen/pull/35/files#diff-d4ea46547782f09756a4dad6c84b2eb54b31e021277a5b11b57dfb42f0778024R1-R17),[[7]](https://github.com/opencodeco/validgen/pull/35/files#diff-4c2ad5fa8c747a1340b2799c942d920678c32dc94fd42ae4851ab2d7b584113aR1-R17),[[8]](https://github.com/opencodeco/validgen/pull/35/files#diff-5ccc7d97788240400d27219897de5ad3ded212044bd2c5664ace8dcf0cd61481R1-R17),[[9]](https://github.com/opencodeco/validgen/pull/35/files#diff-808912661a389a8783e0a1a3e9004f88907a83a92aa4af8dc584dd5b81e5c928R1-R17),[[10]](https://github.com/opencodeco/validgen/pull/35/files#diff-536d4e884065a0d72bdd4643fede3ab342c0923199f05c8b817074a8953e8937R1-R17))Refactoring and Cleanup:
Centralized Struct Definitions: Moved
StructValidGenandStructManualCodingdefinitions into a new shared file (tests/bench/types.go) to improve code organization and reuse. ([tests/bench/types.goR1-R17](https://github.com/opencodeco/validgen/pull/35/files#diff-40f3fae275284e619122ec0026fd149976db57e63c446f04683670857a9915f1R1-R17))File Renaming: Renamed
manual_coding_validator.gotomanual_coding.goto better align with its purpose and removed redundant struct definitions. ([tests/bench/manual_coding.goL10-L17](https://github.com/opencodeco/validgen/pull/35/files#diff-58586c38e83f2309b1a18d4eb10c24d1f709f9ff015adb74f00237be5da51003L10-L17))These updates collectively improve the benchmarking process, enhance code maintainability, and provide a robust framework for comparing
ValidGenwith other validation libraries.