类
public interface ITestAppService : IApplicationService
{
void Test1(List<int> list);
}
public class TestAppService : TESTAppServiceBase, ITestAppService
{
public void Test1(List<int> list)
{
}
}
代码
public string Test(int count)
{
var list = Enumerable.Range(1, 10000).ToList();
var msg = "";
var sw = new Stopwatch();
var test = IocManager.Instance.Resolve<TestAppService>();
sw.Start();
for (int i = 0; i < count; i++)
{
test.Test1(list);
}
msg += $"class: {sw.ElapsedMilliseconds}ms, ";
var itest = IocManager.Instance.Resolve<ITestAppService>();
sw.Restart();
for (int i = 0; i < count; i++)
{
itest.Test1(list);
}
msg += $"interface: {sw.ElapsedMilliseconds}ms, ";
ITestAppService newTest = new TestAppService();
sw.Restart();
for (int i = 0; i < count; i++)
{
newTest.Test1(list);
}
msg += $"new interface: {sw.ElapsedMilliseconds}ms, ";
return msg;
}
结果
调用 Test(1000)
class: 0ms, interface: 7321ms, new interface: 0ms,