예제 #1
0
        public void Run()
        {
            var duration    = Duration.TotalSeconds;
            var threadCount = ParallelRunner.ThreadCount;

            using (Writer.Section($"Test settings:")) {
                Writer.AppendMetric("Duration", duration * 1000, "ms");
                Writer.AppendMetric("Thread count", threadCount, "");
                Writer.AppendMetric("Unit size", UnitAllocator.UnitSize, "B");
            }
            Writer.AppendLine();

            var totalCount = 0L;

            for (var pass = 0; pass < PassCount; pass++)
            {
                var runner     = ParallelRunner.New(i => new UnitAllocator(Duration));
                var allocators = runner.Run();
                totalCount = Math.Max(totalCount, allocators.Sum(a => a.AllocationCount));
            }

            var totalSize             = totalCount * UnitAllocator.UnitSize;
            var totalSizeWithOverhead = totalCount * (UnitAllocator.UnitSize + GarbageAllocator.ObjectSize);

            using (Writer.Section($"Allocation speed:")) {
                Writer.AppendMetric("Operations per second", totalCount / Sizes.Mega / duration, "M/s");
//                Writer.AppendMetric("Bytes per second", totalSize  / duration / Sizes.GB, "GB/s");
//                Writer.AppendMetric("Bytes per second (incl. overhead)", totalSizeWithOverhead  / duration / Sizes.GB, "GB/s");
            }
            Writer.AppendLine();
        }
예제 #2
0
        public static void AppendHistogram(this IndentedTextWriter writer,
                                           string title, double[] data, string unit,
                                           string format        = "0.####",
                                           double[] percentiles = null)
        {
            percentiles = percentiles ?? DefaultPercentiles;

            IndentedTextWriter AppendLine(string s) => writer.AppendLine(s);
            IndentedTextWriter AppendMetric(string name, double value) => writer.AppendMetric(name, value, unit);

            using (writer.Section($"{title}")) {
                if (data.Length == 0)
                {
                    AppendLine("No data.");
                    return;
                }

                AppendLine("Min .. Max:");
                using (writer.Indent()) {
                    AppendMetric("Min", data.Min());
                    AppendMetric("Avg", data.Average());
                    AppendMetric("Max", data.Max());
                }
                if (percentiles.Length > 0)
                {
                    AppendLine("Percentiles:");
                    using (writer.Indent()) {
                        var maxIndex = data.Length - 1;
                        foreach (var p in percentiles)
                        {
                            AppendMetric($"{p:#.##}%", data[(int)(maxIndex * p / 100)]);
                        }
                    }
                }
            }
        }