Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PROFILE
- using System;
- using System.Diagnostics;
- using System.Numerics;
- namespace profiletest
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stopwatch total = Stopwatch.StartNew();
- #if PROFILE
- Stopwatch initn = new Stopwatch();
- Stopwatch initf = new Stopwatch();
- Stopwatch loop = new Stopwatch();
- Stopwatch body = new Stopwatch();
- initn.Start();
- #endif
- int n = 100;
- #if PROFILE
- initn.Stop();
- initf.Start();
- #endif
- BigInteger f = 1;
- #if PROFILE
- initf.Stop();
- loop.Start();
- #endif
- for (int i = n; i > 1; i--)
- {
- #if PROFILE
- loop.Stop();
- body.Start();
- #endif
- f *= i;
- #if PROFILE
- body.Stop();
- loop.Start();
- #endif
- }
- #if PROFILE
- loop.Stop();
- #endif
- total.Stop();
- Console.WriteLine(f);
- Console.ReadLine();
- Console.WriteLine(" Line | Ticks");
- Console.WriteLine("------------------------------|----------");
- Console.WriteLine(" |");
- #if PROFILE
- Console.WriteLine("int n = 100; |{0,10}", initn.ElapsedTicks);
- Console.WriteLine("BigInteger f = 1; |{0,10}", initf.ElapsedTicks);
- Console.WriteLine("for (int i = n; i > 1; i--) |{0,10}", loop.ElapsedTicks);
- Console.WriteLine("{ |");
- Console.WriteLine(" f *= i; |{0,10}", body.ElapsedTicks);
- Console.WriteLine("} |");
- Console.WriteLine(" |");
- #endif
- Console.WriteLine("Total time: |{0,10}", total.ElapsedTicks);
- #if PROFILE
- Console.WriteLine("Stopwatch overhead: |{0,10}", total.ElapsedTicks - initn.ElapsedTicks - initf.ElapsedTicks - loop.ElapsedTicks - body.ElapsedTicks);
- #endif
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment