public static T Time <T>(string op, Func <T> f)
        {
            using (var monitor = new PerformanceMonitor())
            {
                var result = f();

                var swElapsedMilliseconds = monitor.ElapsedMilliseconds;

                Console.WriteLine($"{op} took {swElapsedMilliseconds}ms");
                return(result);
            }
        }
Esempio n. 2
0
        public void should_work_with_Actions_as_well()
        {
            using (var t = new TestConsole())
            {
                Action action = () =>
                {
                    Thread.Sleep(300);
                };

                PerformanceMonitor.Time("some op", action);

                string result = t;
                result.Should().Contain("some op took 300ms");
            }
        }
Esempio n. 3
0
        public void should_calculate_execution_time()
        {
            using (var t = new TestConsole())
            {
                Func <int> func = () =>
                {
                    Thread.Sleep(300);
                    return(100);
                };

                PerformanceMonitor.Time("some op", func);

                string result = t;
                result.Should().Contain("some op took 300ms");
            }
        }