Benchmarks
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 BenchmarkDotNet. The full source code of the benchmark is available here.
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 here.
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.
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.
Last updated