public void TestForLoop() { var targets = new BenchmarkTarget(); targets.ForLoop(10); Assert.IsTrue(true); }
private static IEnumerable <Benchmark> CompetitionToBenchmarks(object competition, BenchmarkSettings defaultSettings) { if (defaultSettings == null) { defaultSettings = BenchmarkSettings.CreateDefault(); } var targetType = competition.GetType(); var methods = targetType.GetMethods(); 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, benchmarkAttribute.Description); AssertBenchmarkMethodHasCorrectSignature(methodInfo); AssertBenchmarkMethodIsAccessible(methodInfo); AssertBenchmarkMethodIsNotDeclaredInGeneric(methodInfo); AssertBenchmarkMethodIsNotGeneric(methodInfo); foreach (var task in BenchmarkTask.Resolve(methodInfo, defaultSettings)) { yield return(new Benchmark(target, task)); } } } }
public void TestIf() { var targets = new BenchmarkTarget(); var actual = targets.If(true); var expected = true; Assert.AreEqual(expected, actual); }
public void TestWhileLoop() { var targets = new BenchmarkTarget(); var actual = targets.WhileLoop(10); var expected = 10; Assert.AreEqual(expected, actual); }
public void TestModulo() { var targets = new BenchmarkTarget(); var actual = targets.Modulo(3, 2); var expected = 1; Assert.AreEqual(expected, actual); }
public void TestMultiplication() { var targets = new BenchmarkTarget(); var actual = targets.Multiplication(2, 2); var expected = 4; Assert.AreEqual(expected, actual); }
public void TestDivision() { var targets = new BenchmarkTarget(); var actual = targets.Division(2, 1); var expected = 2; Assert.AreEqual(expected, actual); }
public void TestSubtraction() { var targets = new BenchmarkTarget(); var actual = targets.Subtraction(5, 4); var expected = 1; Assert.AreEqual(expected, actual); }
public void TestLogicalOr() { var targets = new BenchmarkTarget(); var actual = targets.LogicalOr(0, 1); var expected = true; Assert.AreEqual(expected, actual); }
public void TestMoreThan() { var targets = new BenchmarkTarget(); var actual = targets.MoreThan(10, 5); var expected = true; Assert.AreEqual(expected, actual); }
public void TestArray() { var targets = new BenchmarkTarget(); var actual = targets.ConstructArray(); int[] expected = { 1, 2, 3, 6, 4, 2, 5, 3, 2, 6, 7 }; Assert.Equal(expected, actual); }
public void TestAddition1() { var targets = new BenchmarkTarget(); var actual = targets.Addition(5, 4); var expected = 9; Assert.Equal(expected, actual); }
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 fields = type.GetFields().Select(f => new { f.Name, Attribute = f.ResolveAttribute <ParamsAttribute>(), IsStatic = f.IsStatic, }); var properties = type.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(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)); } } } } }
public void TestLessThan() { var targets = new BenchmarkTarget(); var actual = false; actual = targets.LessThan(5, 10); var expected = true; Assert.AreEqual(expected, actual); }
public Benchmark(BenchmarkTarget target, BenchmarkTask task) { Target = target; Task = task; }