Esempio n. 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 = Counter.Value;

            p.Evaluate(0.0);    // do the first iteration.
            long delta = Counter.Value - start;

            Console.WriteLine("Overhead = {0:f2} seconds", (double)delta / Counter.Frequency);
            Console.WriteLine("Eval({0}) = {1}", value, p.Evaluate(value));

            int limit = 100000;

            start = Counter.Value;

            // Evaluate the polynomial the required number of
            // times.
            double result = 0;

            for (int i = 0; i < limit; i++)
            {
                result += p.Evaluate(value);
            }
            delta = Counter.Value - start;

            double ips = (double)limit * ((double)Counter.Frequency / (double)delta);

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

            return(ips);
        }