<commit_before>﻿using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Semver.Utility;

namespace Semver.Benchmarks
{
    [SimpleJob(RuntimeMoniker.Net461)]
    [SimpleJob(RuntimeMoniker.NetCoreApp21)]
    [SimpleJob(RuntimeMoniker.NetCoreApp31)]
    public class DecimalDigits
    {
        [Params(99, 999, 999_999, int.MaxValue)]
        public int Number { get; set; }

        [Benchmark]
        public int Standard()
        {
            return Number.DecimalDigits();
        }

        [Benchmark]
        public int Logarithm()
        {
            return LogarithmDecimalDigits(Number);
        }

        [Benchmark]
        public int String()
        {
            return StringDecimalDigits(Number);
        }

        [Benchmark]
        public int While()
        {
            return WhileDecimalDigits(Number);
        }

        private static int LogarithmDecimalDigits(int n)
        {
            return (int)Math.Floor(Math.Log10(n) + 1);
        }

        private static int StringDecimalDigits(int n)
        {
            return n.ToString().Length;
        }

        public static int WhileDecimalDigits(int n)
        {
            int digits = 1;
            while ((n /= 10) != 0) ++digits;
            return digits;
        }
    }
}<commit_msg>prevent inlining in DecimalDigits benchmark<commit_after>﻿using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Semver.Utility;

namespace Semver.Benchmarks
{
    [SimpleJob(RuntimeMoniker.Net461)]
    [SimpleJob(RuntimeMoniker.NetCoreApp21)]
    [SimpleJob(RuntimeMoniker.NetCoreApp31)]
    public class DecimalDigits
    {
        [Params(99, 999, 999_999, int.MaxValue)]
        public int Number { get; set; }

        [Benchmark]
        public int Standard()
        {
            return Number.DecimalDigits();
        }

        [Benchmark]
        public int Logarithm()
        {
            return LogarithmDecimalDigits(Number);
        }

        [Benchmark]
        public int String()
        {
            return StringDecimalDigits(Number);
        }

        [Benchmark]
        public int While()
        {
            return WhileDecimalDigits(Number);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static int LogarithmDecimalDigits(int n)
        {
            return (int)Math.Floor(Math.Log10(n) + 1);
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static int StringDecimalDigits(int n)
        {
            return n.ToString().Length;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        public static int WhileDecimalDigits(int n)
        {
            int digits = 1;
            while ((n /= 10) != 0) ++digits;
            return digits;
        }
    }
}
{'fraction_non_alphanumeric': 0.09154929577464789, 'fraction_numerical': 0.017605633802816902, 'mean_word_length': 1.8901322482197356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2344033', 'n_tokens_mistral': 871, 'n_tokens_neox': 806, 'n_words': 167}