public void TimeExpireTest()
        {
            for (var max = 100; max < 200; max++)
            {
                var   profiler   = new Profiler(new ProfilerOptions(ProfilerType.SampleAverageTimeMs, max, 10, null), nameof(TimeExpireTest));
                Int64 totalCount = 0;
                var   avgCount   = 0;
                for (var i = 0; i < 100; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    var a = ConcurrentRandom.Next(1, 100);
                    profiler.AddTimeMeasurement(r, a);
                }
                Thread.Sleep(10);
                for (var i = 0; i < max - 100; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    var a = ConcurrentRandom.Next(1, 100);
                    totalCount += r;
                    avgCount   += a;
                    profiler.AddTimeMeasurement(r, a);
                }

                if (avgCount != 0 && totalCount != 0)
                {
                    var avg = ((double)totalCount / 10_000D) / avgCount;
                    Assert.InRange(profiler.GetValue(), avg - 0.1D, avg + 0.1D);
                }

                Assert.Equal(String.Format("{0:0,0.00}", profiler.GetValue()), profiler.GetText());

                Assert.Throws <ArgumentOutOfRangeException>(() => profiler.AddTimeMeasurement(1, 0));
                Assert.Throws <ArgumentOutOfRangeException>(() => profiler.AddTimeMeasurement(1, -1));
            }
        }
        public void MaxHistoryTest()
        {
            for (var max = 1; max < 100; max++)
            {
                var   profiler   = new Profiler(new ProfilerOptions(ProfilerType.SampleAverageTimeMs, max, 1000, null), nameof(MaxHistoryTest));
                Int64 totalCount = 0;
                var   avgCount   = 0;
                for (var i = 0; i < 1000; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    var a = ConcurrentRandom.Next(1, 100);
                    profiler.AddTimeMeasurement(r, a);
                }
                for (var i = 0; i < max; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    var a = ConcurrentRandom.Next(1, 100);
                    totalCount += r;
                    avgCount   += a;
                    profiler.AddTimeMeasurement(r, a);
                }

                var avg = ((double)totalCount / 10_000D) / avgCount;
                Assert.InRange(profiler.GetValue(), avg - 0.1D, avg + 0.1D);
                Assert.Equal(String.Format("{0:0,0.00}", profiler.GetValue()), profiler.GetText());
            }
        }
        public void TotalTest()
        {
            for (var max = 1; max < 100; max++)
            {
                var profiler = new Profiler(new ProfilerOptions(ProfilerType.TimeTotal, max, 1000, null), nameof(TotalTest));
                var queue    = new Queue <int>();
                for (var i = 0; i < 1000; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    queue.Enqueue(r);
                    profiler.AddTimeMeasurement(r, Math.Abs(ConcurrentRandom.NextInt32()));
                }

                var s = queue.Select(s => (Int64)s).Sum() / 10_000D;
                Assert.Equal(s, profiler.GetValue());
                Assert.Equal(String.Format("{0:0,0.00}", s), profiler.GetText());
            }
        }
示例#4
0
        public void FormatterTest()
        {
            for (var round = 0; round < 100; round++)
            {
                var profiler = new Profiler(new ProfilerOptions(ProfilerType.SampleAverageTimeMs, 100, 100, "{0:0}"),
                                            nameof(FormatterTest));
                Int64 totalCount = 0;
                var   avgCount   = 0;
                for (var i = 0; i < 100; i++)
                {
                    var r = ConcurrentRandom.NextInt32();
                    var a = ConcurrentRandom.Next(1, 100);
                    totalCount += r;
                    avgCount   += a;
                    profiler.AddTimeMeasurement(r, a);
                }

                var avg = Math.Round(((double)totalCount / 10_000D) / avgCount);
                Assert.Equal(avg.ToString(), profiler.GetText());
            }
        }