Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("This program tests the performance of squaring numbers.\n");
- Console.WriteLine("Iterations | a*a Time | Math.Pow(a, 2) Time");
- Console.WriteLine("-----------|----------|--------------------");
- int iterations = 100000;
- double number = 3092d;
- double result;
- while(true)
- {
- Stopwatch timera = Stopwatch.StartNew();
- for(int i = 0; i < iterations; i++)
- {
- result = number*number;
- }
- timera.Stop();
- Stopwatch timerb = Stopwatch.StartNew();
- for(int i = 0; i < iterations; i++)
- {
- result = Math.Pow(number, 2);
- }
- timerb.Stop();
- Console.WriteLine(" {0,9} | {1,8} | {2}", iterations, timera.ElapsedMilliseconds.ToString(),
- timerb.ElapsedMilliseconds.ToString());
- iterations += 100000;
- System.Threading.Thread.Sleep(500); // make sure that we don't crash the server
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement