<commit_before>﻿using System.Text;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Mathematics;

namespace BenchmarkDotNet.Extensions
{
    public static class StatisticsExtensions
    {
        private static string NullSummaryMessage = "<Empty statistic (N=0)>";

        public static string ToStr(this Statistics s)
        {
            if (s == null)
                return NullSummaryMessage;
            var builder = new StringBuilder();
            var errorPercent = (s.StandardError / s.Mean * 100).ToStr();
            builder.AppendLine($"Mean = {s.Mean.ToStr()}, StdErr = {s.StandardError.ToStr()} ({errorPercent}%); N = {s.N}, StdDev = {s.StandardDeviation.ToStr()}");
            builder.AppendLine($"Min = {s.Min.ToStr()}, Q1 = {s.Q1.ToStr()}, Median = {s.Median.ToStr()}, Q3 = {s.Q3.ToStr()}, Max = {s.Max.ToStr()}");
            builder.AppendLine($"IQR = {s.InterquartileRange.ToStr()}, LowerFence = {s.LowerFence.ToStr()}, UpperFence = {s.UpperFence.ToStr()}");
            builder.AppendLine($"ConfidenceInterval = {s.ConfidenceInterval.ToStr()}");
            builder.AppendLine($"Skewness = {s.Skewness}, Kurtosis = {s.Kurtosis}");
            return builder.ToString();
        }

        public static string ToTimeStr(this Statistics s, TimeUnit unit = null)
        {
            if (s == null)
                return NullSummaryMessage;
            if (unit == null)
                unit = TimeUnit.GetBestTimeUnit(s.Mean);
            var builder = new StringBuilder();
            var errorPercent = (s.StandardError / s.Mean * 100).ToStr();
            builder.AppendLine($"Mean = {s.Mean.ToTimeStr(unit)}, StdErr = {s.StandardError.ToTimeStr(unit)} ({errorPercent}%); N = {s.N}, StdDev = {s.StandardDeviation.ToTimeStr(unit)}");
            builder.AppendLine($"Min = {s.Min.ToTimeStr(unit)}, Q1 = {s.Q1.ToTimeStr(unit)}, Median = {s.Median.ToTimeStr(unit)}, Q3 = {s.Q3.ToTimeStr(unit)}, Max = {s.Max.ToTimeStr(unit)}");
            builder.AppendLine($"IQR = {s.InterquartileRange.ToTimeStr(unit)}, LowerFence = {s.LowerFence.ToTimeStr(unit)}, UpperFence = {s.UpperFence.ToTimeStr(unit)}");
            builder.AppendLine($"ConfidenceInterval = {s.ConfidenceInterval.ToTimeStr(unit)}");
            builder.AppendLine($"Skewness = {s.Skewness}, Kurtosis = {s.Kurtosis}");
            return builder.ToString();
        }
    }
}<commit_msg>Used ToStr to make statistics builder culture invariant (fixed #307)<commit_after>﻿using System.Text;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Mathematics;

namespace BenchmarkDotNet.Extensions
{
    public static class StatisticsExtensions
    {
        private static string NullSummaryMessage = "<Empty statistic (N=0)>";

        public static string ToStr(this Statistics s)
        {
            if (s == null)
                return NullSummaryMessage;
            var builder = new StringBuilder();
            string errorPercent = (s.StandardError / s.Mean * 100).ToStr();
            builder.AppendLine($"Mean = {s.Mean.ToStr()}, StdErr = {s.StandardError.ToStr()} ({errorPercent}%); N = {s.N}, StdDev = {s.StandardDeviation.ToStr()}");
            builder.AppendLine($"Min = {s.Min.ToStr()}, Q1 = {s.Q1.ToStr()}, Median = {s.Median.ToStr()}, Q3 = {s.Q3.ToStr()}, Max = {s.Max.ToStr()}");
            builder.AppendLine($"IQR = {s.InterquartileRange.ToStr()}, LowerFence = {s.LowerFence.ToStr()}, UpperFence = {s.UpperFence.ToStr()}");
            builder.AppendLine($"ConfidenceInterval = {s.ConfidenceInterval.ToStr()}");
            builder.AppendLine($"Skewness = {s.Skewness.ToStr()}, Kurtosis = {s.Kurtosis.ToStr()}");
            return builder.ToString();
        }

        public static string ToTimeStr(this Statistics s, TimeUnit unit = null)
        {
            if (s == null)
                return NullSummaryMessage;
            if (unit == null)
                unit = TimeUnit.GetBestTimeUnit(s.Mean);
            var builder = new StringBuilder();
            string errorPercent = (s.StandardError / s.Mean * 100).ToStr();
            builder.AppendLine($"Mean = {s.Mean.ToTimeStr(unit)}, StdErr = {s.StandardError.ToTimeStr(unit)} ({errorPercent}%); N = {s.N}, StdDev = {s.StandardDeviation.ToTimeStr(unit)}");
            builder.AppendLine($"Min = {s.Min.ToTimeStr(unit)}, Q1 = {s.Q1.ToTimeStr(unit)}, Median = {s.Median.ToTimeStr(unit)}, Q3 = {s.Q3.ToTimeStr(unit)}, Max = {s.Max.ToTimeStr(unit)}");
            builder.AppendLine($"IQR = {s.InterquartileRange.ToTimeStr(unit)}, LowerFence = {s.LowerFence.ToTimeStr(unit)}, UpperFence = {s.UpperFence.ToTimeStr(unit)}");
            builder.AppendLine($"ConfidenceInterval = {s.ConfidenceInterval.ToTimeStr(unit)}");
            builder.AppendLine($"Skewness = {s.Skewness.ToStr()}, Kurtosis = {s.Kurtosis.ToStr()}");
            return builder.ToString();
        }
    }
}
{'fraction_non_alphanumeric': 0.16127703398558188, 'fraction_numerical': 0.006797116374871267, 'mean_word_length': 2.928802588996764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4439423', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1523, 'n_words': 275}