首页 > 代码库 > Ioc 比较

Ioc 比较

/// <summary>
/// install-package Ninject
/// install-package autofac
/// install-package Munq.IocContainer
/// install-package Unity
/// </summary>

 

static void Cost(string ioc,Action action)                {                                              var stopwatch = new Stopwatch();                        stopwatch.Start();                         for (int i=0;i<10000;i++)                        {                                 action();                        }                        stopwatch.Stop();                        var ticks = stopwatch.ElapsedMilliseconds;                        Console.WriteLine(ioc + ": " + (ticks / 1000.00).ToString()+" ms");                }

 

 static void Cost(string ioc,Action action)                {                        var stopwatch = new Stopwatch();                        stopwatch.Start();                         for (int i=0;i<10000;i++)                        {                                Task.Run(action); // 换成多线程                        }                        stopwatch.Stop();                        var ticks = stopwatch.ElapsedMilliseconds;                        Console.WriteLine(ioc + ": " + (ticks / 1000.00).ToString()+" ms");                }