Пример #1
0
        CodeTimer(bool startFresh, ITestOutputHelper output,
                  string format, params object[] args)
        {
            this.output = output;
            if (startFresh)
            {
                PrepareForOperation();
            }

            this.testText = string.Format(format, args);

            this.gen0Start = GC.CollectionCount(0);
            this.gen1Start = GC.CollectionCount(1);
            this.gen2Start = GC.CollectionCount(2);

            // Get the time before returning so that any code above doesn't
            // impact the time.
            this.startTime = Stopwatch.GetTimestamp();
#if NET45
            var handle = Process.GetCurrentProcess().Handle;
#else
            var handle = Process.GetCurrentProcess().SafeHandle.DangerousGetHandle();
#endif
            this.startCycles = CycleTime.Process(new SafeWaitHandle(handle, false));
        }
Пример #2
0
        public void Dispose()
        {
            ulong elapsedCycles = CycleTime.Process(new SafeWaitHandle(Process.GetCurrentProcess().Handle, false)) - this.startCycles;

            long elapsedTime = Stopwatch.GetTimestamp() - this.startTime;

            long milliseconds = elapsedTime * 1000 / Stopwatch.Frequency;

            if (false == string.IsNullOrEmpty(this.testText))
            {
                this.output.WriteLine("{0}", this.testText);
                this.output.WriteLine("    {0,7:N0}ms {1,11:N0}Kc (G0={2,4}, G1={3,4}, G2={4,4})",
                                      milliseconds,
                                      elapsedCycles / 1000,
                                      GC.CollectionCount(0) - this.gen0Start,
                                      GC.CollectionCount(1) - this.gen1Start,
                                      GC.CollectionCount(2) - this.gen2Start);
            }
        }