Exemple #1
0
        /// <summary>
        /// Times the evaluation of a polynomial
        /// </summary>
        /// <param name="p">The polynomial to evaluate</param>
        public static double TimeEvaluate(Polynomial p)
        {
            double value = 2.0;

            Console.WriteLine("{0}", p.GetType().Name);
            // Time the first iteration. This one is done
            // separately so that we can figure out the startup
            // overhead separately...
            long        start = Stopwatch.GetTimeStamp();
            IPolynomial iPoly = p.GetEvaluate();
            long        delta = Stopwatch.GetTimeStamp() - start;

            Console.WriteLine("Overhead = {0:f2} seconds",
                              (double)delta / Stopwatch.Frequency);
            Console.WriteLine("Eval({0}) = {1}", value, iPoly.Evaluate(value));
            int       limit = 100000;
            Stopwatch timer = Stopwatch.StartNew();
            // Evaluate the polynomial the required number of
            // times.
            double result = 0;

            for (int i = 0; i < limit; i++)
            {
                result += iPoly.Evaluate(value);
            }
            timer.Stop();
            double ips = (double)limit / (double)timer.ElapsedMilliseconds / 1000D;

            Console.WriteLine("Evalutions/Second = {0:f0}", ips);
            Console.WriteLine();
            return(ips);
        }