danielpalme / IocPerformance

Performance comparison of .NET IoC containers
https://danielpalme.github.io/IocPerformance
Apache License 2.0
874 stars 157 forks source link

Add vs-mef adapter #124

Closed AArnott closed 5 years ago

AArnott commented 5 years ago

Closes #120

danielpalme commented 5 years ago

Thanks. Will merge tomorrow.

danielpalme commented 5 years ago

Version 16.3.4-alpha seems not to be published on Nuget. Where can I find it?

AArnott commented 5 years ago

You can see the feed in the nuget.config file that I added to your repo. The web UI for it is here.

AArnott commented 5 years ago

Once it's pushed to nuget.org we can remove the nuget.config file entry. But I would recommend you keep the nuget.config file as every repo should declare its dependencies.

danielpalme commented 5 years ago

Thanks. Visual Studio did not recognize the file. I had to reload the solution to solve this.

AArnott commented 5 years ago

I had to reload the solution to solve this.

Quite right. Consider voting up this issue: https://github.com/NuGet/Home/issues/1538

danielpalme commented 5 years ago

Does the benchmark work on your machine?

I get an exception on this benchmark: https://github.com/danielpalme/IocPerformance/blob/0f79d8c00c71ac1696373755465f47b9372f00b1/IocPerformance/Benchmarks/Advanced/06_Generics_Benchmark.cs#L15

System.InvalidOperationException The sequence contains no elements

Stacktrace:

IocPerformance.exe!IocPerformance.Adapters.VSMefContainerAdapter.Resolve(System.Type type) Line 36  C#
IocPerformance.exe!IocPerformance.Benchmarks.Advanced.Generics_06_Benchmark.MethodToBenchmark(IocPerformance.Adapters.IContainerAdapter container) Line 15  C#
IocPerformance.exe!IocPerformance.Benchmarks.Benchmark.Warmup(IocPerformance.Adapters.IContainerAdapter container) Line 43  C#
IocPerformance.exe!IocPerformance.ContainerAdapterRuntime.Run(System.Type containerType, System.Collections.Generic.List<IocPerformance.Benchmarks.BenchmarkResult> existingBenchmarkResults) Line 40   C#
[External Code] 
IocPerformance.exe!IocPerformance.Program.Main(string[] args) Line 44   C#
AArnott commented 5 years ago

I haven't actually run it completely (it takes a while to execute). So I'll check and fix issues.

danielpalme commented 5 years ago

Should fail pretty fast. The Warmup method executes every benchmark once before starting the "real" test.

If you use this code for ContainerAdapterFactory.cs, it should fail within seconds:

using System;
using System.Collections.Generic;
using System.Linq;
using IocPerformance.Adapters;

namespace IocPerformance
{
    internal static class ContainerAdapterFactory
    {
        public static IEnumerable<IContainerAdapter> CreateAdapters()
        {
            //yield return new NoContainerAdapter();

            var containers = typeof(ContainerAdapterFactory).Assembly.GetTypes()
                 .Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Contains(typeof(IContainerAdapter)))
                 .Where(t => !t.Equals(typeof(NoContainerAdapter)))
                 .Where(t => t.Equals(typeof(VSMefContainerAdapter)))
                 .Select(t => Activator.CreateInstance(t))
                 .Cast<IContainerAdapter>()
                 .OrderBy(c => c.Name);

            if (containers.Count() != containers.Select(b => b.Name).Distinct().Count())
            {
                var duplicateNames = containers
                    .GroupBy(b => b.Name)
                    .Where(g => g.Count() > 1)
                    .Select(g => g.Key);

                throw new InvalidOperationException(string.Format(
                    "ContainerAdapters must have unique names, the following names are used several times: {0}",
                    string.Join(", ", duplicateNames)));
            }

            foreach (var container in containers)
            {
                yield return container;
            }
        }
    }
}
danielpalme commented 5 years ago

I merged your PR with SupportGeneric => false