Skip to content

Commit 40c191f

Browse files
committed
Mapper Speed test added
1 parent 37a26e4 commit 40c191f

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

samples/ValidationRulesTest/ValidationRulesTest/Models/UserValidator.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,35 @@ public bool Validate()
4040

4141
public User Map()
4242
{
43-
//return new User
44-
//{
45-
// Name = this.Name.Value,
46-
// LastName = this.LastName.Value,
47-
// Email = this.Email.Value
48-
//};
49-
50-
return this.MapValidator<User, UserValidator>();
43+
var stopper = new System.Diagnostics.Stopwatch();
44+
var testRuns = 1000; // 1 second
45+
46+
stopper.Start();
47+
48+
// Simple Manual Mapper
49+
var manualMapperUser = new User
50+
{
51+
Name = this.Name.Value,
52+
LastName = this.LastName.Value,
53+
Email = this.Email.Value
54+
};
55+
56+
stopper.Stop();
57+
58+
var time1 = stopper.Elapsed.TotalMilliseconds / (double)testRuns;
59+
System.Console.WriteLine("ManualMapper: " + time1); // Elapsed time: 0.002
60+
61+
stopper.Restart();
62+
63+
// Extension Mapper with simple Model
64+
var extMapperUser = this.MapValidator<User, UserValidator>();
65+
66+
stopper.Stop();
67+
68+
var time2 = stopper.Elapsed.TotalMilliseconds / (double)testRuns;
69+
System.Console.WriteLine("ExtensionMapper: " + time2); // Elapsed time: 0.013
70+
71+
return manualMapperUser;
5172
}
5273
}
5374
}

0 commit comments

Comments
 (0)