Skip to content
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

Really slow benchmark, am I wrong? #413

Open
frederikhors opened this issue Nov 26, 2020 · 1 comment
Open

Really slow benchmark, am I wrong? #413

frederikhors opened this issue Nov 26, 2020 · 1 comment

Comments

@frederikhors
Copy link

Why is asaskevich/govalidator so much slower in the below code? Am I wrong?

package main

import (
	"fmt"
	"time"

	"github.com/asaskevich/govalidator"
	"github.com/go-playground/validator/v10"
)

// User contains user information
type User struct {
	FirstName string `valid:"required" validate:"required"`
	LastName  string `valid:"required" validate:"required"`
	Age       int32  `valid:"range(0|130)" validate:"gte=0,lte=130"`
	Email     string `valid:"required,email" validate:"required,email"`
	Street    string `valid:"required" validate:"required"`
	City      string `valid:"required" validate:"required"`
	Planet    string `valid:"required" validate:"required"`
	Phone     string `valid:"required" validate:"required"`
}

var validate *validator.Validate

const iterations = 10000

func main() {
	validate = validator.New()

	user := &User{
		FirstName: "Badger",
		LastName:  "Smith",
		Age:       80,
		City:      "string",
		Email:     "Badger.Smith@gmail.com",
		Street:    "Eavesdown Docks",
		Planet:    "Persphone",
		Phone:     "none",
	}

	println("govalidator.Struct (asaskevich):")
	before := time.Now()
	for i := 0; i < iterations; i++ {
		govalidator.ValidateStruct(user)
	}
	fmt.Println(time.Since(before))

	println("validate.Struct (go-playground):")
	before = time.Now()
	for i := 0; i < iterations; i++ {
		validate.Struct(user)
	}
	fmt.Println(time.Since(before))
}

Result:

govalidator.Struct (asaskevich):
135.03ms
validate.Struct (go-playground):
17.9687ms
@sergeyglazyrindev
Copy link

Hello guys!
I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back
Link to my repo: create issue there and we'll discuss it.

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

No branches or pull requests

2 participants