public double Benchmark(IterationParams iteration) { // It seems like Assert Failiures inside the Benchmark, don't actually fail the test, although // there is a message printed in the test output. Probably because we create a new instance of // the class inside the Benchmark, we don't use the same one as the test runner? // Or maybe because the Benchmark runner swallows the exceptions, so the Unit-test runner can't see them?! Assert.NotNull(iteration); if (iteration.Count == 0) { _iterationsCounter = 0; } if (_iterationsCounter != 0) { Assert.True(iteration.Count > _iterationsCounter, "Expected current: " + iteration.Count + " to be > than previous: " + _iterationsCounter); } if (iteration.TotalCount != 0) { Assert.True(iteration.Count <= iteration.TotalCount, "Expected Count: " + iteration.Count + " to be <= TotalCount: " + iteration.TotalCount); } _iterationsCounter = iteration.Count; _demoTestRunCount++; return(Math.Sqrt(123.456)); }
public unsafe int GetSquareStackAlloc(IterationParams iteration) { int *someNumbers = stackalloc int[ArraySize]; int value = (int)iteration.Count % ArraySize; for (int i = 0; i < ArraySize; ++i) { someNumbers[i] = value; } return(someNumbers[value]); }
public int GetSquareHeapAlloc(IterationParams iteration) { int[] someNumbers = new int[ArraySize]; int value = (int)iteration.Count % ArraySize; for (int i = 0; i < someNumbers.Length; ++i) { someNumbers[i] = value; } return(someNumbers[value]); }