using System; using System.Collections.Generic; using System.Diagnostics;
namespace AlgorithmTest09_实现栈Stack { class Program { public static long TextStack(IStack<int> stack, int N) { Stopwatch t = new Stopwatch(); t.Start(); for (int i = 0; i < N; i++) { stack.Push(i); } for (int i = 0; i < N; i++) { stack.Pop(); } t.Stop(); return t.ElapsedMilliseconds; } static void Main(string[] args) { #region 测试性能 int N = 10000000; Array1Stack<int> array1Stack = new Array1Stack<int>(N); long t1 = TextStack(array1Stack, N); Console.WriteLine("array1Stack'Time:{0}ms", t1);
LinkedList1Stack<int> linked = new LinkedList1Stack<int>(); long t2 = TextStack(linked, N); Console.WriteLine("linked'Time:{0}ms", t2);
Stack<int> stack = new Stack<int>(); Stopwatch t3 = new Stopwatch(); t3.Start(); for (int i = 0; i < N; i++) { stack.Push(i); } for (int i = 0; i < N; i++) { stack.Pop(); } t3.Stop(); Console.WriteLine("stack'Time:{0}ms", t3.ElapsedMilliseconds); #endregion Console.ReadKey(); } } }
|