Пример #1
0
        public void CanUseMemoryMonitor()
        {
            var monitor = new MemoryMonitor();

            monitor.Value.Should().Be(0);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            using (monitor.Observe())
            {
            }

            var value1 = monitor.Value;
            value1.Should().NotBe(0);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            using (monitor.Observe())
            {
                var list = new List<long>();
                for (var i = 0L; i < 10000L; i++)
                {
                    list.Add(i);
                }
            }

            var value2 = monitor.Value;
            value2.Should().NotBe(0);

            (value1 < value2).Should().BeTrue();
        }
Пример #2
0
        public IDisposable Subscribe(IObserver <PerfTestResult> observer)
        {
            if (ignoreFirstRunDueToJITting)
            {
                this.setUpMethod(this.start);
                try
                {
                    this.testMethod();
                }
                catch (Exception ex)
                {
                }
                this.tearDownMethod();
            }

            var time   = new DurationMonitor();
            var memory = new MemoryMonitor();

            for (var i = this.start; i < this.end; i += this.step)
            {
                var ok = true;

                var descriptor = this.descriptorMethod(i);
                this.setUpMethod(i);

                // clean memory
                if (this.triggerGCBeforeEachTest)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                }

                using (time.Observe())
                    using (memory.Observe())
                    {
                        try
                        {
                            this.testMethod();
                        }
                        catch (Exception ex)
                        {
                            ok = false;
                            observer.OnNext(PerfTestResultFactory.Instance.FaultResult(descriptor, ex));
                        }
                    }

                this.tearDownMethod();
                if (ok)
                {
                    observer.OnNext(PerfTestResultFactory.Instance.PerfResult(time.Value, memory.Value, descriptor));
                }
            }

            return(new DisposableScope());
        }
Пример #3
0
        public void CanUseMemoryMonitor()
        {
            var monitor = new MemoryMonitor();

            monitor.Value.Should().Be(0);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            using (monitor.Observe())
            {
            }

            var value1 = monitor.Value;

            value1.Should().NotBe(0);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            using (monitor.Observe())
            {
                var list = new List <long>();
                for (var i = 0L; i < 10000L; i++)
                {
                    list.Add(i);
                }
            }

            var value2 = monitor.Value;

            value2.Should().NotBe(0);

            (value1 < value2).Should().BeTrue();
        }