Skip to content

Instantly share code, notes, and snippets.

@HristoKolev
Created December 5, 2016 18:02
Show Gist options
  • Save HristoKolev/60122acceb2064ef831c5b6cb193fa50 to your computer and use it in GitHub Desktop.
Save HristoKolev/60122acceb2064ef831c5b6cb193fa50 to your computer and use it in GitHub Desktop.
namespace ConsoleApplication8
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
internal class Program
{
private static void Main(string[] args)
{
IList<Model> instances = new List<Model>();
Random random = new Random();
for (int i = 0; i < 100 * 1000; i++)
{
instances.Add(new Model
{
Property1 = random.Next().ToString(),
Property2 = random.Next().ToString(),
Property3 = random.Next().ToString(),
Property4 = random.Next().ToString(),
Property5 = random.Next().ToString(),
Property6 = random.Next().ToString(),
Property7 = random.Next().ToString(),
Property8 = random.Next().ToString(),
Property9 = random.Next().ToString(),
Property10 = random.Next().ToString(),
Property11 = random.Next().ToString(),
Property12 = random.Next().ToString(),
Property13 = random.Next().ToString(),
Property14 = random.Next().ToString(),
Property15 = random.Next().ToString(),
Property16 = random.Next().ToString(),
Property17 = random.Next().ToString(),
Property18 = random.Next().ToString(),
Property19 = random.Next().ToString(),
Property20 = random.Next().ToString()
});
}
var results = new List<ValidationResult>();
var stopwatch = Stopwatch.StartNew();
foreach (var instance in instances)
{
var context = new ValidationContext(instance, null, null);
Validator.TryValidateObject(instance, context, results);
}
Console.WriteLine(stopwatch.Elapsed);
}
}
public class Model
{
[Required]
public string Property1 { get; set; }
[RegularExpression("[0-9]+")]
public string Property10 { get; set; }
[Required]
public string Property11 { get; set; }
[MinLength(2)]
public string Property12 { get; set; }
[MaxLength(11)]
public string Property13 { get; set; }
[Required]
public string Property14 { get; set; }
[RegularExpression("[0-9]+")]
public string Property15 { get; set; }
[MinLength(2)]
public string Property16 { get; set; }
[MaxLength(11)]
public string Property17 { get; set; }
[Required]
public string Property18 { get; set; }
[RegularExpression("[0-9]+")]
public string Property19 { get; set; }
[MinLength(2)]
public string Property2 { get; set; }
[RegularExpression("[0-9]+")]
public string Property20 { get; set; }
[MaxLength(11)]
public string Property3 { get; set; }
[Required]
public string Property4 { get; set; }
[RegularExpression("[0-9]+")]
public string Property5 { get; set; }
[MinLength(2)]
public string Property6 { get; set; }
[MaxLength(11)]
public string Property7 { get; set; }
[Required]
public string Property8 { get; set; }
[RegularExpression("[0-9]+")]
public string Property9 { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment