// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using Lib; namespace PerfTestBMDN { public class PerfTest { private static Random rng = new Random(); [Benchmark] public void TestBuiltin() { double a = rng.NextDouble() * 1000.0; double sqrta = Work.SqrtBuiltin(a); if(Math.Abs(a - sqrta * sqrta) > 0.0000001) throw new Exception("Ooops"); } [Benchmark] public void TestNewton() { double a = rng.NextDouble() * 1000.0; double sqrta = Work.SqrtNewton(a); if(Math.Abs(a - sqrta * sqrta) > 0.0000001) throw new Exception("Ooops"); } } public class Program { public static void Main(string[] args) { BenchmarkRunner.Run(typeof(PerfTest).Assembly); Console.ReadKey(); } } }