forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceControllerPerfTests.cs
More file actions
78 lines (64 loc) · 1.89 KB
/
ServiceControllerPerfTests.cs
File metadata and controls
78 lines (64 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Diagnostics;
using Funq;
using NUnit.Framework;
using ServiceStack.ServiceHost.Tests.Support;
using ServiceStack.ServiceHost.Tests.TypeFactory;
namespace ServiceStack.ServiceHost.Tests
{
[Ignore("Perf Test Only")]
[TestFixture]
public class ServiceControllerPerfTests
{
private const int Times = 100000;
[Test]
public void RunAll()
{
With_Funq_and_Expressions();
With_Native_Funq();
With_Funq_and_Reflection(); //Very slow
}
[Test]
public void With_Native_Funq()
{
var container = new Container();
container.Register<IFoo>(c => new Foo());
container.Register<IBar>(c => new Bar());
container.Register(
c => new AutoWireService(c.Resolve<IFoo>()) {
Bar = c.Resolve<IBar>()
}).ReusedWithin(ReuseScope.None);
Console.WriteLine("With_Native_Funq(): {0}", Measure(() => container.Resolve<AutoWireService>(), Times));
}
[Test]
[Ignore("Slow to run")]
public void With_Funq_and_Reflection()
{
var container = new Container();
container.Register<IFoo>(c => new Foo());
container.Register<IBar>(c => new Bar());
var funqlet = new ReflectionTypeFunqContainer(container);
funqlet.Register(typeof(AutoWireService));
Console.WriteLine("With_Funq_and_Reflection(): {0}", Measure(() => container.Resolve<AutoWireService>(), Times));
}
[Test]
public void With_Funq_and_Expressions()
{
var container = new Container();
container.Register<IFoo>(c => new Foo());
container.Register<IBar>(c => new Bar());
container.RegisterAutoWiredType(typeof(AutoWireService));
Console.WriteLine("With_Funq_and_Expressions(): {0}", Measure(() => container.Resolve<AutoWireService>(), Times));
}
private static long Measure(Action action, int iterations)
{
GC.Collect();
var watch = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
action();
}
return watch.ElapsedTicks;
}
}
}