Esempio n. 1
0
 public TaskAttribute(
     int processCount = 1,
     BenchmarkMode mode = BenchmarkMode.Throughput,
     BenchmarkPlatform platform = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework = BenchmarkFramework.HostFramework,
     int warmupIterationCount = 5,
     int targetIterationCount = 10
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework, BenchmarkExecutor.Classic, BenchmarkRuntime.Clr, string.Empty, warmupIterationCount, targetIterationCount));
 }
 public TaskAttribute(
     int processCount               = 1,
     BenchmarkMode mode             = BenchmarkMode.Throughput,
     BenchmarkPlatform platform     = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework   = BenchmarkFramework.HostFramework,
     int warmupIterationCount       = 5,
     int targetIterationCount       = 10
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework, BenchmarkToolchain.Classic, BenchmarkRuntime.Clr, warmupIterationCount, targetIterationCount));
 }
Esempio n. 3
0
 public TaskAttribute(
     int processCount = 1,
     BenchmarkMode mode = BenchmarkMode.Throughput,
     BenchmarkPlatform platform = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework = BenchmarkFramework.HostFramework,
     int warmupIterationCount = 5,
     int targetIterationCount = 10
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework),
         new BenchmarkSettings(warmupIterationCount, targetIterationCount));
 }
 public BenchmarkTaskAttribute(
     int processCount               = 3,
     BenchmarkMode mode             = BenchmarkMode.Throughput,
     BenchmarkPlatform platform     = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework   = BenchmarkFramework.HostFramework,
     int warmupIterationCount       = 5,
     int targetIterationCount       = 10
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework),
         new BenchmarkSettings(warmupIterationCount, targetIterationCount));
 }
 public BenchmarkTaskAttribute(
     int processCount = 3,
     BenchmarkMode mode = BenchmarkMode.Throughput,
     BenchmarkPlatform platform = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework = BenchmarkFramework.HostFramework,
     BenchmarkToolchain toolchain = BenchmarkToolchain.Classic,
     BenchmarkRuntime runtime = BenchmarkRuntime.Clr,
     int warmupIterationCount = 5,
     int targetIterationCount = 10
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework, toolchain, runtime, warmupIterationCount, targetIterationCount));
 }
 public BenchmarkTaskAttribute(
     int processCount = 3,
     BenchmarkMode mode = BenchmarkMode.Throughput,
     BenchmarkPlatform platform = BenchmarkPlatform.HostPlatform,
     BenchmarkJitVersion jitVersion = BenchmarkJitVersion.HostJit,
     BenchmarkFramework framework = BenchmarkFramework.HostFramework,
     BenchmarkExecutor executor = BenchmarkExecutor.Classic,
     BenchmarkRuntime runtime = BenchmarkRuntime.Clr,
     string runtimeVersion = null,
     int warmupIterationCount = 5,
     int targetIterationCount = 10,
     int[] intParams = null
     )
 {
     Task = new BenchmarkTask(
         processCount,
         new BenchmarkConfiguration(mode, platform, jitVersion, framework, executor, runtime, runtimeVersion, warmupIterationCount, targetIterationCount),
         new BenchmarkParametersSets(intParams));
 }
        public static IEnumerable<Benchmark> TypeToBenchmarks(Type type)
        {
            var methods = type.GetMethods();
            var setupMethod = methods.FirstOrDefault(m => m.ResolveAttribute<SetupAttribute>() != null);
            if (setupMethod != null)
            {
                // setupMethod is optional, but if it's there it must have the correct signature, accessibility, etc
                AssertMethodHasCorrectSignature("Setup", setupMethod);
                AssertMethodIsAccessible("Setup", setupMethod);
                AssertMethodIsNotGeneric("Setup", setupMethod);
            }

            // If there is one, get the single Field or Property that has the [Params(..)] attribute
            var reflectionFlags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
            var fields = type.GetFields(reflectionFlags).Select(f => new
            {
                f.Name,
                Attribute = f.ResolveAttribute<ParamsAttribute>(),
                Private = f.IsPrivate,
                IsStatic = f.IsStatic,
            });
            var properties = type.GetProperties(reflectionFlags).Select(p => new
            {
                p.Name,
                Attribute = p.ResolveAttribute<ParamsAttribute>(),
                Private = p.GetSetMethod() == null ? true : false,
                IsStatic = p.GetSetMethod() != null ? p.GetSetMethod().IsStatic : false
            });
            var fieldOrProperty = fields.Concat(properties).FirstOrDefault(i => i.Attribute != null);

            var privateField = fields.FirstOrDefault(f => f.Attribute != null && f.Private);
            if (privateField != null)
                throw new InvalidOperationException($"Field \"{privateField.Name}\" must be public if it has the [Params(..)] attribute applied to it");

            var privateProperty = properties.FirstOrDefault(p => p.Attribute != null && p.Private);
            if (privateProperty != null)
                throw new InvalidOperationException($"Property \"{privateProperty.Name}\" must be public and writable if it has the [Params(..)] attribute applied to it");

            for (int i = 0; i < methods.Length; i++)
            {
                var methodInfo = methods[i];
                var benchmarkAttribute = methodInfo.ResolveAttribute<BenchmarkAttribute>();
                if (benchmarkAttribute != null)
                {
                    var target = new BenchmarkTarget(type, methodInfo, setupMethod, benchmarkAttribute.Description);
                    AssertMethodHasCorrectSignature("Benchmark", methodInfo);
                    AssertMethodIsAccessible("Benchmark", methodInfo);
                    AssertMethodIsNotGeneric("Benchmark", methodInfo);
                    foreach (var task in BenchmarkTask.Resolve(methodInfo))
                    {
                        if (fieldOrProperty == null)
                        {
                            yield return new Benchmark(target, task);
                        }
                        else
                        {
                            var parametersSets = new BenchmarkParametersSets(fieldOrProperty.Name, fieldOrProperty.IsStatic, fieldOrProperty.Attribute.Args);
                            // All the properties of BenchmarkTask and it's children are immutable, so cloning a BenchmarkTask like this should be safe
                            var newTask = new BenchmarkTask(task.ProcessCount, task.Configuration, parametersSets);
                            yield return new Benchmark(target, newTask);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 public Benchmark(BenchmarkTarget target, BenchmarkTask task)
 {
     Target = target;
     Task = task;
 }
Esempio n. 9
0
        private static IEnumerable<Benchmark> CompetitionToBenchmarks(object competition, BenchmarkSettings defaultSettings)
        {
            if (defaultSettings == null)
                defaultSettings = BenchmarkSettings.CreateDefault();
            var targetType = competition.GetType();
            var methods = targetType.GetMethods();
            var setupMethod = methods.FirstOrDefault(m => m.ResolveAttribute<SetupAttribute>() != null);
            if (setupMethod != null)
            {
                // setupMethod is optional, but if it's there it must have the correct signature, accessibility, etc
                AssertMethodHasCorrectSignature("Setup", setupMethod);
                AssertMethodIsAccessible("Setup", setupMethod);
                AssertMethodIsNotDeclaredInGeneric("Setup", setupMethod);
                AssertMethodIsNotGeneric("Setup", setupMethod);
            }

            // If there is one, get the single Field or Property that has the [Params(..)] attribute
            var fields = targetType.GetFields().Select(f => new
                {
                    f.Name,
                    Attribute = f.ResolveAttribute<ParamsAttribute>(),
                    IsStatic = f.IsStatic,
                });
            var properties = targetType.GetProperties().Select(f => new
                {
                    f.Name,
                    Attribute = f.ResolveAttribute<ParamsAttribute>(),
                    IsStatic = f.GetSetMethod().IsStatic
                });
            var fieldOrProperty = fields.Concat(properties).FirstOrDefault(i => i.Attribute != null);

            for (int i = 0; i < methods.Length; i++)
            {
                var methodInfo = methods[i];
                var benchmarkAttribute = methodInfo.ResolveAttribute<BenchmarkAttribute>();
                if (benchmarkAttribute != null)
                {
                    var target = new BenchmarkTarget(targetType, methodInfo, setupMethod, benchmarkAttribute.Description);
                    AssertMethodHasCorrectSignature("Benchmark", methodInfo);
                    AssertMethodIsAccessible("Benchmark", methodInfo);
                    AssertMethodIsNotDeclaredInGeneric("Benchmark", methodInfo);
                    AssertMethodIsNotGeneric("Benchmark", methodInfo);
                    foreach (var task in BenchmarkTask.Resolve(methodInfo, defaultSettings))
                    {
                        if (fieldOrProperty == null)
                        {
                            yield return new Benchmark(target, task);
                        }
                        else
                        {
                            var @params = new BenchmarkParams(fieldOrProperty.Name, fieldOrProperty.IsStatic, fieldOrProperty.Attribute.Args);
                            // All the properties of BenchmarkTask and it's children are immutable, so cloning a BenchmarkTask like this should be safe
                            var newTask = new BenchmarkTask(task.ProcessCount, task.Configuration, task.Settings, @params);
                            yield return new Benchmark(target, newTask);
                        }
                    }
                }
            }
        }