Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

Closes #26

This PR introduces significant enhancements to the benchmarking infrastructure for the ValidGen project, 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 between ValidGen and the Validator project.

Benchmarking Enhancements:

  • New cmpbenchtests Target in Makefile: Added a cmpbenchtests target to automate the process of generating, building, and running benchmark tests comparing ValidGen and Validator. 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, showcasing ValidGen'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 compare ValidGen and Validator performance 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:

  • Generated Validation Code: Added auto-generated validation functions for ValidGen to handle specific validation scenarios (e.g., required, eq, neq, etc.). These files are generated by ValidGen and 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 StructValidGen and StructManualCoding definitions 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.go to manual_coding.go to 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 ValidGen with other validation libraries.

@alexgarzao alexgarzao requested a review from Copilot July 22, 2025 00:46
@alexgarzao alexgarzao self-assigned this Jul 22, 2025

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot July 23, 2025 00:12
Copy link
Contributor

Copilot AI left a 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 cmpbenchtests target 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
Copy link

Copilot AI Jul 23, 2025

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).

Suggested change
// nin
{
TestType: "StringNotIn",
FieldType: "string",
ValidGenValidate: "not_in=ab cd ef",
ValidatorValidate: "not_oneof=ab cd ef",
ValidInput: "gh",
},

Copilot uses AI. Check for mistakes.
package benchtests

type StructValidGen struct {
FirstName string `valid:"required"`
Copy link

Copilot AI Jul 23, 2025

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.

Copilot generated this review using guidance from repository custom instructions.
@alexgarzao alexgarzao merged commit 6700d33 into main Jul 23, 2025
1 check passed
@alexgarzao alexgarzao deleted the 26-benchmark-tests-validgen-vs-validator branch July 23, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Benchmark tests between ValidGen and Validator

4 participants