Example #1
0
        private static IEnumerable<MethodInfo> GetSuitableMethods(IProject project)
        {
            var typesToExclude = new[] {typeof (Project), typeof (IProject), typeof (Object)};

            return from method in project.GetType().GetMethods()
                   where typesToExclude.None(t => t.Equals(method.DeclaringType))
                   where !method.IsSpecialName
                   select method;
        }
        static void Main()
        {
            string[] values = new[] { "One", "Two" };
            if (values.Contains("Three"))
            {
                Console.WriteLine("true");
            }
            else
            {
                Console.WriteLine("false");
            }

            // set up code
            int[] value = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            Console.WriteLine(Measure(value));

            value = null;
            bool re = value.None(i => i > 1000);

            #if !DEBUG
            var log = new long[30];
            Stopwatch stopwatch = new Stopwatch();
            for (int repeat = 0, i = Repeat; repeat < log.Length; repeat++, i = Repeat)
            {
                stopwatch.Restart();
                while (i-- > 0)
                {
                    Measure(value);
                }
                stopwatch.Stop();

                long ticks = stopwatch.ElapsedTicks;
                long milliseconds = stopwatch.ElapsedMilliseconds;
                long microseconds = stopwatch.ElapsedTicks * 1000000 / Stopwatch.Frequency;
                long nanoseconds = stopwatch.ElapsedTicks * 1000000000 / Stopwatch.Frequency;

                Console.WriteLine("{0} ticks, {1} milliseconds, {2} microseconds, {3} nanoseconds", ticks, milliseconds, microseconds, nanoseconds);
                log[repeat] = nanoseconds;
            }

            double median = log.OrderBy(ns => ns).Skip(log.Length / 2).Take(1).First() / Repeat;

            long medianMilliseconds = (long)(median / 1000000000);
            long medianMicroseconds = (long)(median / 1000000);
            long medianNanoseconds = (long)median;

            Console.WriteLine("\r\n\r\nMedian: {0} milliseconds, {1} microseconds, {2} nanoseconds", medianMilliseconds, medianMicroseconds, medianNanoseconds);
            #endif
            Console.ReadLine();
        }