Пример #1
0
        public static Measurement Measure(string name, [NotNull] Action action, int blocks)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            var cpuUserTimeBefore   = CurrentProcess.UserProcessorTime;
            var cpuKernelTimeBefore = CurrentProcess.PrivilegedProcessorTime;
            var memoryBefore        = MemoryStatistics.TakeCurrent();
            var stopwatch           = Stopwatch.StartNew();

            action();

            stopwatch.Stop();
            var memoryAfter        = MemoryStatistics.TakeCurrent();
            var cpuUserTimeAfter   = CurrentProcess.UserProcessorTime;
            var cpuKernelTimeAfter = CurrentProcess.PrivilegedProcessorTime;

            var gcDelta = MemoryStatistics.Delta(memoryBefore, memoryAfter);

            return(new Measurement(
                       name,
                       blocks,
                       stopwatch.Elapsed,
                       (cpuKernelTimeAfter - cpuKernelTimeBefore),
                       (cpuUserTimeAfter - cpuUserTimeBefore),
                       gcDelta));
        }