Validly
Github
  • Introduction
  • Getting Started
    • Quickstart
    • Installation
    • Configuration
    • Benchmarks
  • Basics
    • Defining Validations
    • Handling Validation Result
    • Automatically Added Validators
  • Validators
    • Build-in Validators
      • Common
      • Strings
      • Numbers
      • Enums
      • Collections
    • Creating Custom Validators
    • Manual Validation
      • CustomValidation Attribute
      • Before And After Hooks
Powered by GitBook
On this page
  • Compared Libraries
  • Results
  • Input
  • Execution Time
  • Memory Usage
  1. Getting Started

Benchmarks

PreviousConfigurationNextDefining Validations

Last updated 6 months ago

A comprehensive benchmark comparing Validly with other popular .NET validation libraries, focusing on both performance (execution time) and memory allocation efficiency. The benchmark was conducted using . The full source code of the benchmark is available .

Compared Libraries

  • System.ComponentModel.DataAnnotations,

  • ,

Results

BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.2314)

CPU: AMD Ryzen 7 PRO 8840HS

.NET SDK 8.0.404 [Host] : .NET 8.0.11 (8.0.1124.51707), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI .NET 8.0 : .NET 8.0.11 (8.0.1124.51707), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI

Raw data are stored .

Input

In all the charts, the NumberOfInvalidValues is represented on the X-axis. This parameter corresponds to the number of invalid values in the validated object. Three distinct instances were used for validation:

  • All – Every value was invalid, triggering error messages for all validation rules.

  • None – All values were valid, resulting in no error messages.

  • One – Only a single value was invalid, causing a validation error for just that specific value.

public IEnumerable<CreateUserRequest> Objects =>
    new CreateUserRequest[]
    {
        // "None"
        new()
        {
            Username = "username",
            Password = "S0m3_pa55w0rd#",
            Email = "email@gmail.com",
            Age = 25,
            FirstName = "Tony",
            LastName = "Stark"
        },
        // "One"
        new()
        {
            Username = "",
            Password = "S0m3_pa55w0rd#",
            Email = "email@gmail.com",
            Age = 25,
            FirstName = "Tony",
            LastName = "Stark"
        },
        // "All"
        new()
        {
            Username = "Tom",
            Password = "pass",
            Email = "email[at]gmail.com",
            Age = 16,
            FirstName = "",
            LastName = ""
        },
};

Execution Time

As seen in the results, the clear winner in terms of performance is Validot when using their IsValid() validation method. This method exits the validation process early, avoiding the generation of error messages. For the "none" instance (where all values are valid), the execution time is similar to that of other libraries because the validation process has to evaluate all rules for all properties, as there are no invalid values to trigger an early exit. Notably, Validly does not yet implement an early exit functionality, which is why its performance is slightly affected in this case. However, when excluding the early-exit variant of Validot, Validly outperforms the other libraries.

The Y-axis is logarithmic.

Memory Usage

In the bar chart below, you may notice that Validly is not visible. It appears as the first bar, but it is absent from the chart because its allocated memory is zero.

The instance of the FluentValidation validator was cached to ensure that only the .Validate() method call was benchmarked, eliminating any potential overhead from repeated object initialization.

The instance of the Validot validator was also cached.

BenchmarkDotNet
here
FluentValidation
Validot
here
Execution time in nano seconds for a single validation of one object
Allocated memory in bytes for a single validation of one object