Created
December 21, 2013 04:39
-
-
Save adamchester/8065483 to your computer and use it in GitHub Desktop.
AutoFixture specimen creation performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class SpecimenWithEverything | |
{ | |
public enum MyEnum | |
{ | |
MyFirstValue, | |
MySecondValue, | |
MyThridValue, | |
} | |
public string String1 { get; set; } | |
public int? Int1 { get; set; } | |
public bool? Bool1 { get; set; } | |
public DateTime? DateTime1 { get; set; } | |
public Guid? Guid1 { get; set; } | |
public ChildFields Child1 { get; set; } | |
public IEnumerable<ChildFields> Children { get; set; } | |
public ChildFields[] ChildrenArray { get; set; } | |
public Dictionary<int, ChildFields> ChildrenDictionary { get; set; } | |
public class ChildFields | |
{ | |
#pragma warning disable 649 | |
public string ChildString; | |
public object ChildObject; | |
public DateTime? ChildDateTime; | |
public MyEnum? MyEnum1; | |
public MyEnum? MyEnum2; | |
#pragma warning restore 649 | |
} | |
} | |
private class SpecimenWithAttributes | |
{ | |
[StringLength(10)] | |
public string String1 { get; set; } | |
[StringLength(10)] | |
public string String2 { get; set; } | |
[StringLength(10)] | |
public string String3 { get; set; } | |
[StringLength(10)] | |
public string String4 { get; set; } | |
[StringLength(10)] | |
public string String5 { get; set; } | |
[Range(5, 100)] | |
public int? Int1 { get; set; } | |
[Range(5, 100)] | |
public int? Int2 { get; set; } | |
[Range(5, 100)] | |
public int? Int3 { get; set; } | |
[Range(5, 100)] | |
public int? Int4 { get; set; } | |
[Range(5, 100)] | |
public int? Int5 { get; set; } | |
} | |
class ImmutableSpecimenWithReadonlyFields | |
{ | |
public ImmutableSpecimenWithReadonlyFields(int field1, | |
string field2, DateTime field3, Guid field4, bool field5, decimal field6) | |
{ | |
Field1 = field1; | |
Field2 = field2; | |
Field3 = field3; | |
Field4 = field4; | |
Field5 = field5; | |
Field6 = field6; | |
} | |
#pragma warning disable 649 | |
public readonly int Field1; | |
public readonly string Field2; | |
public readonly DateTime Field3; | |
public readonly Guid Field4; | |
public readonly bool Field5; | |
public readonly decimal Field6; | |
#pragma warning restore 649 | |
} | |
[Fact] | |
public void Create10000ImmutableSpecimensQuickly() | |
{ | |
var sut = new Fixture(); | |
var sw = new Stopwatch(); | |
sw.Start(); | |
for (int requestNumber = 0; requestNumber < 10000; requestNumber++) | |
{ | |
var value = sut.Create<ImmutableSpecimenWithReadonlyFields>(); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0}, Elapsed: {1}", MethodBase.GetCurrentMethod().Name, sw.Elapsed); | |
} | |
[Fact] | |
public void Instantiate1000FixturesQuickly() | |
{ | |
// Fixture setup | |
var sw = new Stopwatch(); | |
sw.Start(); | |
for (int instanceNumber = 0; instanceNumber < 1000; instanceNumber++) | |
{ | |
var sut = new Fixture(); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0}, Elapsed: {1}", MethodBase.GetCurrentMethod().Name, sw.Elapsed); | |
} | |
[Fact] | |
public void Create1000SpecimensQuickly() | |
{ | |
// Fixture setup | |
var sut = new Fixture(); | |
var sw = new Stopwatch(); | |
sw.Start(); | |
for (int requestNumber = 0; requestNumber < 1000; requestNumber++) | |
{ | |
var value = sut.Create<SpecimenWithEverything>(); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0}, Elapsed: {1}", MethodBase.GetCurrentMethod().Name, sw.Elapsed); | |
} | |
[Fact] | |
public void Create1000SpecimensWithAttrsQuickly() | |
{ | |
// Fixture setup | |
var sut = new Fixture(); | |
var sw = new Stopwatch(); | |
sw.Start(); | |
for (int requestNumber = 0; requestNumber < 1000; requestNumber++) | |
{ | |
var value = sut.Create<SpecimenWithAttributes>(); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0}, Elapsed: {1}", MethodBase.GetCurrentMethod().Name, sw.Elapsed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment