我刚刚注意到Castle Windsor容器在我的工作电脑(Core i5 1st gen)上需要400ms,在我的家用电脑(i5 haswell)上需要200ms才能创建,注册几个组件并解析一个没有依赖关系的对象。
Unity在不到50ms的时间里做同样的事情
这对我来说似乎是非常错误的。我的VS2013在1秒内从SSD启动,我相信CW更复杂,更有资源(是的,我知道这些是橘子和苹果)。应用程序的启动时间是我想保持尽可能短的时间。
为了加快速度,我能做些什么吗?有没有人遇到同样的问题?
以下是代码段:
class Program
{
static void Main(string[] args)
{
var sw = Stopwatch.StartNew();
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(
Component.For<IItemFactory>().AsFactory(),
Component.For<IItem>().ImplementedBy<Item>().LifestyleTransient());
var factory = container.Resolve<IItemFactory>();
sw.Stop();
Console.WriteLine(sw.Elapsed); // 00:00:00.1991386
}
}
public interface IItemFactory
{
IItem Create();
}
public class Item : IItem
{
public string Value { get; set; }
}
public interface IItem
{
string Value { get; set; }
}