Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private const double TWO_PI = Math.PI * 2;
- private const int CYCLES = 10000000;
- private const int SEED = 873407789;
- private static double[] RANDOM_NUMBERS;
- static void Main(string[] args)
- {
- //precompile methods of the assembly for better performance
- Tools.PreJitCompile.Methods(System.Reflection.Assembly.GetExecutingAssembly());
- //feeding probe array
- var r = new Random(SEED);
- RANDOM_NUMBERS = new double[CYCLES];
- for (var i = 0L; i < CYCLES; i++)
- {
- RANDOM_NUMBERS[i] = r.NextDouble() * TWO_PI;
- }
- //probe system trig
- BenchSystem(out var systemTime);
- //prepare for usage, one time effort
- UltimateTrigonometry.InitializeTrigonometricTables();
- //probe ultimate trig
- BenchUltimateTrig(out var ultimateTime);
- Console.WriteLine("___________________________");
- Console.WriteLine("Method | Time");
- Console.WriteLine("___________________________\r\n");
- Console.WriteLine("System | {0}", systemTime);
- Console.WriteLine("Ultimate| {0}", ultimateTime);
- Console.WriteLine("\r\nSystem {0}% faster", (int)(ultimateTime / systemTime * 100d) - 100);
- Console.Read();
- }
- private static void BenchSystem(out TimeSpan deltaT)
- {
- var sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- for(var i = 0; i < CYCLES; i++)
- {
- Math.Sin(RANDOM_NUMBERS[i]);
- }
- sw.Stop();
- deltaT = sw.Elapsed;
- }
- private static void BenchUltimateTrig(out TimeSpan deltaT)
- {
- var sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- for (var i = 0; i < CYCLES; i++)
- {
- UltimateTrigonometry.Sine(RANDOM_NUMBERS[i]);
- }
- sw.Stop();
- deltaT = sw.Elapsed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement