Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize threshold of BigInteger.Parse #97101

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

kzrnm
Copy link
Contributor

@kzrnm kzrnm commented Jan 17, 2024

BigInteger.Parse(new string('9', n)) is slow when n is less than or equal to 20000. I have adjusted the value of Number.s_naiveThreshold. It seems optimal to set s_naiveThreshold to ~3200.

parse-large
parse-medium
parse-small

Benchmark result


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3)
13th Gen Intel Core i5-13500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 9.0.100-alpha.1.24055.2
  [Host]     : .NET 9.0.0 (9.0.24.5410), X64 RyuJIT AVX2
  Job-GGYJPI : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-WWRJET : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-WGTAFG : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2


Method Job Toolchain data Mean Error StdDev Ratio RatioSD Code Size
Parse Job-GGYJPI \threshold-20000\corerun.exe 10 45.60 ns 0.738 ns 0.690 ns 1.00 0.00 1,301 B
Parse Job-WWRJET \threshold-200\corerun.exe 10 44.64 ns 0.181 ns 0.169 ns 0.98 0.02 1,301 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 10 46.52 ns 0.754 ns 0.706 ns 1.02 0.02 1,301 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 1000 5,795.24 ns 102.845 ns 96.201 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 1000 6,977.25 ns 91.240 ns 85.346 ns 1.20 0.03 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 1000 5,693.01 ns 41.608 ns 38.920 ns 0.98 0.02 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 10000 421,049.09 ns 2,501.488 ns 2,339.893 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 10000 300,605.59 ns 1,202.674 ns 1,124.982 ns 0.71 0.01 1,912 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 10000 302,896.96 ns 1,347.163 ns 1,194.225 ns 0.72 0.00 1,912 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 100000 11,021,006.47 ns 43,855.362 ns 38,876.636 ns 1.00 0.00 1,910 B
Parse Job-WWRJET \threshold-200\corerun.exe 100000 10,987,397.43 ns 46,058.556 ns 40,829.710 ns 1.00 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 100000 11,019,705.73 ns 37,853.168 ns 35,407.877 ns 1.00 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 15000 923,114.03 ns 1,927.688 ns 1,708.845 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 15000 506,987.02 ns 2,112.473 ns 1,976.009 ns 0.55 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 15000 512,487.95 ns 4,214.187 ns 3,735.767 ns 0.56 0.00 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 200 546.25 ns 3.662 ns 3.425 ns 1.00 0.00 1,323 B
Parse Job-WWRJET \threshold-200\corerun.exe 200 542.25 ns 3.999 ns 3.741 ns 0.99 0.01 1,301 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 200 594.30 ns 9.087 ns 8.500 ns 1.09 0.02 1,323 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 2000 18,861.05 ns 244.683 ns 216.905 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 2000 20,262.46 ns 55.018 ns 45.943 ns 1.07 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 2000 19,282.80 ns 358.565 ns 335.401 ns 1.02 0.02 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 20000 1,642,039.23 ns 26,908.019 ns 23,853.258 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 20000 918,541.43 ns 6,649.921 ns 5,894.982 ns 0.56 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 20000 913,176.52 ns 5,379.492 ns 5,031.980 ns 0.56 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 21000 990,613.79 ns 4,270.432 ns 3,994.565 ns 1.00 0.00 1,907 B
Parse Job-WWRJET \threshold-200\corerun.exe 21000 972,333.43 ns 3,308.060 ns 2,762.380 ns 0.98 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 21000 976,396.97 ns 2,629.997 ns 2,460.101 ns 0.99 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 25000 1,220,008.70 ns 5,987.507 ns 5,600.718 ns 1.00 0.00 1,907 B
Parse Job-WWRJET \threshold-200\corerun.exe 25000 1,209,837.99 ns 5,421.557 ns 5,071.327 ns 0.99 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 25000 1,217,052.27 ns 4,808.584 ns 4,497.952 ns 1.00 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3000 41,862.51 ns 800.256 ns 748.560 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3000 43,036.34 ns 826.021 ns 918.121 ns 1.03 0.02 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3000 40,108.01 ns 166.842 ns 156.064 ns 0.96 0.02 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3100 43,062.93 ns 187.372 ns 175.267 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 3100 43,495.98 ns 151.154 ns 133.995 ns 1.01 0.01 1,906 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3100 42,428.54 ns 172.682 ns 144.197 ns 0.98 0.00 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3190 44,815.35 ns 115.218 ns 96.212 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3190 45,054.97 ns 271.193 ns 253.674 ns 1.00 0.01 1,906 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3190 45,502.33 ns 691.214 ns 646.562 ns 1.01 0.02 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3200 44,732.35 ns 128.450 ns 120.152 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3200 45,064.43 ns 176.626 ns 156.574 ns 1.01 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3200 45,516.23 ns 381.866 ns 338.514 ns 1.02 0.01 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3210 46,742.76 ns 654.699 ns 612.406 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3210 46,056.45 ns 222.297 ns 197.060 ns 0.98 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3210 45,319.98 ns 233.934 ns 207.376 ns 0.97 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3300 48,172.70 ns 254.882 ns 225.946 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3300 46,151.79 ns 156.535 ns 138.764 ns 0.96 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3300 46,575.74 ns 337.154 ns 315.374 ns 0.97 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 4000 70,018.87 ns 190.796 ns 169.135 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 4000 59,450.45 ns 284.232 ns 265.871 ns 0.85 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 4000 59,727.96 ns 258.895 ns 242.171 ns 0.85 0.00 1,906 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 500 1,929.92 ns 10.069 ns 8.926 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 500 2,437.91 ns 12.908 ns 12.074 ns 1.26 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 500 2,062.71 ns 9.490 ns 8.877 ns 1.07 0.01 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 5000 106,056.19 ns 524.458 ns 464.918 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 5000 99,107.96 ns 370.876 ns 346.918 ns 0.93 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 5000 98,501.99 ns 326.673 ns 305.570 ns 0.93 0.00 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 50000 3,637,431.90 ns 12,147.589 ns 11,362.863 ns 1.00 0.00 1,912 B
Parse Job-WWRJET \threshold-200\corerun.exe 50000 3,658,643.39 ns 26,188.345 ns 23,215.286 ns 1.01 0.01 1,912 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 50000 3,634,539.97 ns 31,264.624 ns 29,244.949 ns 1.00 0.01 1,912 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 7500 236,146.59 ns 930.672 ns 870.551 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 7500 167,152.52 ns 973.603 ns 813.002 ns 0.71 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 7500 167,245.00 ns 625.042 ns 584.665 ns 0.71 0.00 1,910 B

Benchmark code

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;
using System.Runtime.InteropServices;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[DisassemblyDiagnoser]
public class Tests
{
    public record Data(int Length)
    {
        public string Text = new string('9', Length);
        public override string ToString() => $"{Length}";
    }
    public IEnumerable<object> NumberStrings()
    {
        yield return new Data(10);
        yield return new Data(200);
        yield return new Data(500);
        yield return new Data(1000);
        yield return new Data(2000);
        yield return new Data(3000);
        yield return new Data(3100);
        yield return new Data(3190);
        yield return new Data(3200);
        yield return new Data(3210);
        yield return new Data(3300);
        yield return new Data(4000);
        yield return new Data(5000);
        yield return new Data(7500);
        yield return new Data(10000);
        yield return new Data(15000);
        yield return new Data(20000);
        yield return new Data(21000);
        yield return new Data(25000);
        yield return new Data(50000);
        yield return new Data(100000);
    }


    [Benchmark]
    [ArgumentsSource(nameof(NumberStrings))]
    public BigInteger Parse(Data data) => BigInteger.Parse(data.Text);
}

Related

#55121 e93dde5

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 17, 2024
@kzrnm kzrnm force-pushed the BigIntegerParseThreshold branch from dfb63a9 to 314d139 Compare January 17, 2024 14:05
@ghost
Copy link

ghost commented Jan 17, 2024

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

BigInteger.Parse(new string('9', n)) is slow when n is less than or equal to 20000. I have adjusted the value of Number.s_naiveThreshold. It seems optimal to set s_naiveThreshold to ~3200.

parse-large
parse-medium
parse-small

Benchmark result


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3)
13th Gen Intel Core i5-13500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 9.0.100-alpha.1.24055.2
  [Host]     : .NET 9.0.0 (9.0.24.5410), X64 RyuJIT AVX2
  Job-GGYJPI : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-WWRJET : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-WGTAFG : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2


Method Job Toolchain data Mean Error StdDev Ratio RatioSD Code Size
Parse Job-GGYJPI \threshold-20000\corerun.exe 10 45.60 ns 0.738 ns 0.690 ns 1.00 0.00 1,301 B
Parse Job-WWRJET \threshold-200\corerun.exe 10 44.64 ns 0.181 ns 0.169 ns 0.98 0.02 1,301 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 10 46.52 ns 0.754 ns 0.706 ns 1.02 0.02 1,301 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 1000 5,795.24 ns 102.845 ns 96.201 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 1000 6,977.25 ns 91.240 ns 85.346 ns 1.20 0.03 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 1000 5,693.01 ns 41.608 ns 38.920 ns 0.98 0.02 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 10000 421,049.09 ns 2,501.488 ns 2,339.893 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 10000 300,605.59 ns 1,202.674 ns 1,124.982 ns 0.71 0.01 1,912 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 10000 302,896.96 ns 1,347.163 ns 1,194.225 ns 0.72 0.00 1,912 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 100000 11,021,006.47 ns 43,855.362 ns 38,876.636 ns 1.00 0.00 1,910 B
Parse Job-WWRJET \threshold-200\corerun.exe 100000 10,987,397.43 ns 46,058.556 ns 40,829.710 ns 1.00 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 100000 11,019,705.73 ns 37,853.168 ns 35,407.877 ns 1.00 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 15000 923,114.03 ns 1,927.688 ns 1,708.845 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 15000 506,987.02 ns 2,112.473 ns 1,976.009 ns 0.55 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 15000 512,487.95 ns 4,214.187 ns 3,735.767 ns 0.56 0.00 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 200 546.25 ns 3.662 ns 3.425 ns 1.00 0.00 1,323 B
Parse Job-WWRJET \threshold-200\corerun.exe 200 542.25 ns 3.999 ns 3.741 ns 0.99 0.01 1,301 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 200 594.30 ns 9.087 ns 8.500 ns 1.09 0.02 1,323 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 2000 18,861.05 ns 244.683 ns 216.905 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 2000 20,262.46 ns 55.018 ns 45.943 ns 1.07 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 2000 19,282.80 ns 358.565 ns 335.401 ns 1.02 0.02 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 20000 1,642,039.23 ns 26,908.019 ns 23,853.258 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 20000 918,541.43 ns 6,649.921 ns 5,894.982 ns 0.56 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 20000 913,176.52 ns 5,379.492 ns 5,031.980 ns 0.56 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 21000 990,613.79 ns 4,270.432 ns 3,994.565 ns 1.00 0.00 1,907 B
Parse Job-WWRJET \threshold-200\corerun.exe 21000 972,333.43 ns 3,308.060 ns 2,762.380 ns 0.98 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 21000 976,396.97 ns 2,629.997 ns 2,460.101 ns 0.99 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 25000 1,220,008.70 ns 5,987.507 ns 5,600.718 ns 1.00 0.00 1,907 B
Parse Job-WWRJET \threshold-200\corerun.exe 25000 1,209,837.99 ns 5,421.557 ns 5,071.327 ns 0.99 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 25000 1,217,052.27 ns 4,808.584 ns 4,497.952 ns 1.00 0.01 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3000 41,862.51 ns 800.256 ns 748.560 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3000 43,036.34 ns 826.021 ns 918.121 ns 1.03 0.02 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3000 40,108.01 ns 166.842 ns 156.064 ns 0.96 0.02 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3100 43,062.93 ns 187.372 ns 175.267 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 3100 43,495.98 ns 151.154 ns 133.995 ns 1.01 0.01 1,906 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3100 42,428.54 ns 172.682 ns 144.197 ns 0.98 0.00 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3190 44,815.35 ns 115.218 ns 96.212 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3190 45,054.97 ns 271.193 ns 253.674 ns 1.00 0.01 1,906 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3190 45,502.33 ns 691.214 ns 646.562 ns 1.01 0.02 2,034 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3200 44,732.35 ns 128.450 ns 120.152 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3200 45,064.43 ns 176.626 ns 156.574 ns 1.01 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3200 45,516.23 ns 381.866 ns 338.514 ns 1.02 0.01 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3210 46,742.76 ns 654.699 ns 612.406 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3210 46,056.45 ns 222.297 ns 197.060 ns 0.98 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3210 45,319.98 ns 233.934 ns 207.376 ns 0.97 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 3300 48,172.70 ns 254.882 ns 225.946 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 3300 46,151.79 ns 156.535 ns 138.764 ns 0.96 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 3300 46,575.74 ns 337.154 ns 315.374 ns 0.97 0.01 1,910 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 4000 70,018.87 ns 190.796 ns 169.135 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 4000 59,450.45 ns 284.232 ns 265.871 ns 0.85 0.00 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 4000 59,727.96 ns 258.895 ns 242.171 ns 0.85 0.00 1,906 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 500 1,929.92 ns 10.069 ns 8.926 ns 1.00 0.00 2,034 B
Parse Job-WWRJET \threshold-200\corerun.exe 500 2,437.91 ns 12.908 ns 12.074 ns 1.26 0.01 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 500 2,062.71 ns 9.490 ns 8.877 ns 1.07 0.01 2,037 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 5000 106,056.19 ns 524.458 ns 464.918 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 5000 99,107.96 ns 370.876 ns 346.918 ns 0.93 0.01 1,910 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 5000 98,501.99 ns 326.673 ns 305.570 ns 0.93 0.00 1,907 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 50000 3,637,431.90 ns 12,147.589 ns 11,362.863 ns 1.00 0.00 1,912 B
Parse Job-WWRJET \threshold-200\corerun.exe 50000 3,658,643.39 ns 26,188.345 ns 23,215.286 ns 1.01 0.01 1,912 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 50000 3,634,539.97 ns 31,264.624 ns 29,244.949 ns 1.00 0.01 1,912 B
Parse Job-GGYJPI \threshold-20000\corerun.exe 7500 236,146.59 ns 930.672 ns 870.551 ns 1.00 0.00 2,037 B
Parse Job-WWRJET \threshold-200\corerun.exe 7500 167,152.52 ns 973.603 ns 813.002 ns 0.71 0.00 1,907 B
Parse Job-WGTAFG \threshold-3200\corerun.exe 7500 167,245.00 ns 625.042 ns 584.665 ns 0.71 0.00 1,910 B

Benchmark code

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;
using System.Runtime.InteropServices;

BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);

[DisassemblyDiagnoser]
public class Tests
{
    public record Data(int Length)
    {
        public string Text = new string('9', Length);
        public override string ToString() => $"{Length}";
    }
    public IEnumerable<object> NumberStrings()
    {
        yield return new Data(10);
        yield return new Data(200);
        yield return new Data(500);
        yield return new Data(1000);
        yield return new Data(2000);
        yield return new Data(3000);
        yield return new Data(3100);
        yield return new Data(3190);
        yield return new Data(3200);
        yield return new Data(3210);
        yield return new Data(3300);
        yield return new Data(4000);
        yield return new Data(5000);
        yield return new Data(7500);
        yield return new Data(10000);
        yield return new Data(15000);
        yield return new Data(20000);
        yield return new Data(21000);
        yield return new Data(25000);
        yield return new Data(50000);
        yield return new Data(100000);
    }


    [Benchmark]
    [ArgumentsSource(nameof(NumberStrings))]
    public BigInteger Parse(Data data) => BigInteger.Parse(data.Text);
}

Author: kzrnm
Assignees: -
Labels:

area-System.Numerics, community-contribution

Milestone: -

@@ -668,7 +668,7 @@ internal static
#else
internal const
#endif
int s_naiveThreshold = 20000;
int s_naiveThreshold = 3200;
Copy link
Member

@tannergooding tannergooding Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ~10627 bits. The other thresholds you measured were 200 (~661 bits) and 20000 (~66436 bits).

Could you also measure:

  • 308 (~1024 bits)
    • This is roughly enough to fit any integral double (64-bit binary float)
  • 616 (~2048 bits)
  • 1233 (~4096 bits)
    • This is approx the upper bound of most RSA key lengths
  • 2466 (~8192 bits)
  • 4932 (~16384 bits)
    • This is roughly enough to fit any integral quad (128-bit binary float)

@tannergooding
Copy link
Member

This likely needs measurement across a few other machines as well.

@kzrnm
Copy link
Contributor Author

kzrnm commented Jan 17, 2024

I added some test cases.

image
image
image
image
image

Benchmark result


BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3)
13th Gen Intel Core i5-13500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 9.0.100-alpha.1.24055.2
  [Host]     : .NET 9.0.0 (9.0.24.5410), X64 RyuJIT AVX2
  Job-JWHCHB : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-HSPWLR : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-XPSQQM : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-FPLNZJ : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-KGUQDB : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-CJQMQG : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-KVUNWZ : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2
  Job-EMOOTD : .NET 9.0.0 (42.42.42.42424), X64 RyuJIT AVX2


Method Job Toolchain data Mean Error StdDev Ratio RatioSD Code Size
Parse Job-JWHCHB \threshold-1233\corerun.exe 10 48.10 ns 0.606 ns 0.567 ns 1.02 0.03 1,301 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 10 47.12 ns 0.910 ns 0.935 ns 1.00 0.00 1,301 B
Parse Job-XPSQQM \threshold-200\corerun.exe 10 44.52 ns 0.225 ns 0.188 ns 0.95 0.02 1,301 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 10 44.58 ns 0.458 ns 0.429 ns 0.95 0.02 1,301 B
Parse Job-KGUQDB \threshold-308\corerun.exe 10 43.74 ns 0.282 ns 0.220 ns 0.93 0.02 1,301 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 10 44.04 ns 0.171 ns 0.160 ns 0.94 0.02 1,301 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 10 44.87 ns 0.379 ns 0.354 ns 0.95 0.02 1,301 B
Parse Job-EMOOTD \threshold-616\corerun.exe 10 44.82 ns 0.340 ns 0.284 ns 0.95 0.02 1,301 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 1000 5,629.94 ns 45.047 ns 39.933 ns 0.98 0.01 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 1000 5,755.23 ns 85.884 ns 71.717 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 1000 6,834.59 ns 133.398 ns 124.781 ns 1.19 0.02 2,925 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 1000 5,617.00 ns 50.802 ns 42.422 ns 0.98 0.01 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 1000 6,698.60 ns 40.097 ns 35.545 ns 1.16 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 1000 5,664.00 ns 82.933 ns 77.576 ns 0.98 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 1000 5,675.85 ns 53.232 ns 49.794 ns 0.99 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 1000 6,719.87 ns 129.496 ns 114.795 ns 1.17 0.02 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 10000 300,342.81 ns 3,800.417 ns 3,554.912 ns 0.72 0.01 2,928 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 10000 415,978.21 ns 2,115.381 ns 1,978.729 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 10000 302,035.56 ns 4,162.174 ns 3,893.300 ns 0.73 0.01 2,928 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 10000 303,666.20 ns 3,765.190 ns 3,521.961 ns 0.73 0.01 2,928 B
Parse Job-KGUQDB \threshold-308\corerun.exe 10000 307,022.69 ns 6,052.318 ns 5,661.342 ns 0.74 0.02 2,928 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 10000 302,155.40 ns 2,534.593 ns 2,116.500 ns 0.73 0.01 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 10000 298,624.81 ns 2,168.790 ns 1,922.575 ns 0.72 0.01 2,928 B
Parse Job-EMOOTD \threshold-616\corerun.exe 10000 305,002.96 ns 4,803.839 ns 4,493.514 ns 0.73 0.01 2,926 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 1223 7,915.69 ns 153.217 ns 170.300 ns 0.99 0.03 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 1223 8,004.41 ns 145.919 ns 136.493 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 1223 10,186.91 ns 186.126 ns 174.102 ns 1.27 0.03 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 1223 7,765.25 ns 22.927 ns 21.446 ns 0.97 0.02 3,191 B
Parse Job-KGUQDB \threshold-308\corerun.exe 1223 10,085.07 ns 52.303 ns 40.835 ns 1.26 0.02 2,925 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 1223 8,110.46 ns 155.096 ns 145.077 ns 1.01 0.02 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 1223 8,052.81 ns 87.332 ns 81.690 ns 1.01 0.02 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 1223 10,263.56 ns 130.760 ns 122.313 ns 1.28 0.03 2,925 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 1233 8,294.91 ns 156.649 ns 146.529 ns 0.99 0.02 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 1233 8,411.09 ns 116.856 ns 109.307 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 1233 10,865.05 ns 209.311 ns 195.790 ns 1.29 0.03 2,925 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 1233 8,262.54 ns 148.284 ns 138.705 ns 0.98 0.02 3,191 B
Parse Job-KGUQDB \threshold-308\corerun.exe 1233 10,807.76 ns 182.521 ns 170.730 ns 1.29 0.03 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 1233 8,407.03 ns 156.245 ns 146.151 ns 1.00 0.02 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 1233 8,265.71 ns 124.342 ns 110.226 ns 0.98 0.02 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 1233 10,544.84 ns 162.335 ns 151.848 ns 1.25 0.03 2,925 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 1243 10,872.32 ns 183.656 ns 171.792 ns 1.33 0.03 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 1243 8,204.14 ns 94.916 ns 88.785 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 1243 10,447.36 ns 106.095 ns 82.832 ns 1.27 0.02 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 1243 8,271.20 ns 162.056 ns 166.420 ns 1.01 0.03 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 1243 10,914.83 ns 214.063 ns 262.889 ns 1.34 0.03 2,925 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 1243 8,303.29 ns 159.068 ns 170.201 ns 1.01 0.03 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 1243 8,057.86 ns 46.200 ns 40.955 ns 0.98 0.01 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 1243 10,693.40 ns 188.236 ns 176.076 ns 1.30 0.03 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 15000 511,225.66 ns 8,420.102 ns 7,876.168 ns 0.56 0.01 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 15000 920,617.53 ns 12,060.825 ns 11,281.703 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 15000 505,476.54 ns 3,904.420 ns 3,652.197 ns 0.55 0.01 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 15000 503,060.02 ns 3,104.689 ns 2,752.226 ns 0.55 0.01 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 15000 513,947.81 ns 9,687.484 ns 9,061.679 ns 0.56 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 15000 516,118.57 ns 10,105.319 ns 13,139.769 ns 0.56 0.02 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 15000 514,486.15 ns 4,850.344 ns 4,050.257 ns 0.56 0.01 2,926 B
Parse Job-EMOOTD \threshold-616\corerun.exe 15000 500,106.68 ns 1,603.945 ns 1,421.856 ns 0.54 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 190 520.36 ns 9.786 ns 11.649 ns 0.98 0.03 1,323 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 190 527.44 ns 7.858 ns 7.350 ns 1.00 0.00 1,301 B
Parse Job-XPSQQM \threshold-200\corerun.exe 190 523.18 ns 9.743 ns 9.569 ns 0.99 0.02 1,323 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 190 534.47 ns 8.282 ns 7.747 ns 1.01 0.02 1,323 B
Parse Job-KGUQDB \threshold-308\corerun.exe 190 528.22 ns 4.649 ns 4.348 ns 1.00 0.02 1,301 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 190 517.55 ns 6.520 ns 5.779 ns 0.98 0.02 1,323 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 190 538.70 ns 9.713 ns 8.611 ns 1.02 0.02 1,323 B
Parse Job-EMOOTD \threshold-616\corerun.exe 190 532.80 ns 7.253 ns 6.430 ns 1.01 0.02 1,323 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 19000 840,423.63 ns 8,245.365 ns 7,309.301 ns 0.54 0.01 2,926 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 19000 1,546,439.66 ns 27,970.704 ns 26,163.814 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 19000 860,529.35 ns 15,201.083 ns 14,219.103 ns 0.56 0.01 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 19000 834,533.04 ns 13,538.045 ns 12,001.125 ns 0.54 0.01 2,926 B
Parse Job-KGUQDB \threshold-308\corerun.exe 19000 838,212.42 ns 12,314.118 ns 10,916.145 ns 0.54 0.01 2,926 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 19000 814,922.64 ns 6,166.800 ns 5,768.429 ns 0.53 0.01 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 19000 819,473.85 ns 4,622.250 ns 4,323.656 ns 0.53 0.01 2,929 B
Parse Job-EMOOTD \threshold-616\corerun.exe 19000 826,329.70 ns 5,751.190 ns 5,098.280 ns 0.53 0.01 2,926 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 200 544.73 ns 3.367 ns 3.150 ns 1.00 0.01 1,323 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 200 545.69 ns 2.176 ns 1.817 ns 1.00 0.00 1,323 B
Parse Job-XPSQQM \threshold-200\corerun.exe 200 543.72 ns 1.622 ns 1.438 ns 1.00 0.00 1,323 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 200 578.25 ns 2.799 ns 2.619 ns 1.06 0.01 1,301 B
Parse Job-KGUQDB \threshold-308\corerun.exe 200 535.92 ns 3.103 ns 2.592 ns 0.98 0.01 1,301 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 200 550.61 ns 10.399 ns 11.558 ns 1.01 0.02 1,323 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 200 591.19 ns 10.417 ns 9.744 ns 1.09 0.02 1,301 B
Parse Job-EMOOTD \threshold-616\corerun.exe 200 557.04 ns 6.314 ns 5.598 ns 1.02 0.01 1,323 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 2000 19,626.53 ns 75.347 ns 62.918 ns 1.05 0.00 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 2000 18,761.91 ns 47.174 ns 39.392 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 2000 19,553.12 ns 56.033 ns 46.790 ns 1.04 0.00 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 2000 18,684.74 ns 85.751 ns 80.212 ns 1.00 0.00 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 2000 19,563.80 ns 69.516 ns 61.625 ns 1.04 0.00 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 2000 18,749.24 ns 96.139 ns 89.928 ns 1.00 0.00 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 2000 18,802.91 ns 96.812 ns 90.558 ns 1.00 0.01 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 2000 19,527.05 ns 123.479 ns 103.111 ns 1.04 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 20000 892,346.71 ns 4,802.949 ns 4,257.689 ns 0.56 0.00 2,926 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 20000 1,607,624.61 ns 5,041.742 ns 4,716.049 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 20000 891,562.91 ns 2,435.977 ns 2,034.151 ns 0.55 0.00 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 20000 896,467.96 ns 2,913.862 ns 2,725.629 ns 0.56 0.00 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 20000 896,090.42 ns 3,116.077 ns 2,914.780 ns 0.56 0.00 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 20000 901,469.32 ns 3,099.894 ns 2,899.643 ns 0.56 0.00 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 20000 902,474.99 ns 2,850.565 ns 2,666.421 ns 0.56 0.00 2,929 B
Parse Job-EMOOTD \threshold-616\corerun.exe 20000 898,473.26 ns 2,966.054 ns 2,629.330 ns 0.56 0.00 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 210 558.01 ns 1.944 ns 1.818 ns 0.98 0.02 1,301 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 210 568.52 ns 10.013 ns 9.366 ns 1.00 0.00 1,301 B
Parse Job-XPSQQM \threshold-200\corerun.exe 210 888.61 ns 4.863 ns 4.549 ns 1.56 0.03 1,301 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 210 570.10 ns 2.595 ns 2.427 ns 1.00 0.01 1,323 B
Parse Job-KGUQDB \threshold-308\corerun.exe 210 597.24 ns 11.516 ns 13.262 ns 1.05 0.02 1,323 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 210 580.07 ns 6.647 ns 5.893 ns 1.02 0.02 1,323 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 210 593.55 ns 10.932 ns 10.225 ns 1.04 0.03 1,323 B
Parse Job-EMOOTD \threshold-616\corerun.exe 210 562.51 ns 4.338 ns 3.846 ns 0.99 0.02 1,301 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 21000 970,999.88 ns 4,472.594 ns 4,183.667 ns 1.00 0.01 2,926 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 21000 969,244.45 ns 7,907.409 ns 7,396.595 ns 1.00 0.00 2,926 B
Parse Job-XPSQQM \threshold-200\corerun.exe 21000 959,171.72 ns 2,796.086 ns 2,615.461 ns 0.99 0.01 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 21000 959,306.85 ns 3,048.292 ns 2,851.374 ns 0.99 0.01 2,926 B
Parse Job-KGUQDB \threshold-308\corerun.exe 21000 955,066.09 ns 3,096.845 ns 2,896.791 ns 0.99 0.01 2,926 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 21000 963,378.44 ns 3,788.138 ns 3,543.427 ns 0.99 0.01 2,926 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 21000 964,761.23 ns 2,607.385 ns 2,438.950 ns 1.00 0.01 2,926 B
Parse Job-EMOOTD \threshold-616\corerun.exe 21000 964,535.08 ns 4,324.514 ns 4,045.153 ns 1.00 0.01 2,926 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 2456 30,354.24 ns 135.392 ns 120.022 ns 1.12 0.01 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 2456 27,203.03 ns 144.413 ns 135.084 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 2456 30,385.07 ns 91.016 ns 85.136 ns 1.12 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 2456 27,200.63 ns 145.677 ns 136.266 ns 1.00 0.01 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 2456 30,402.16 ns 88.790 ns 78.710 ns 1.12 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 2456 27,283.01 ns 122.121 ns 114.232 ns 1.00 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 2456 27,074.10 ns 121.576 ns 107.774 ns 1.00 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 2456 30,123.77 ns 70.887 ns 66.307 ns 1.11 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 2466 30,656.47 ns 164.508 ns 153.881 ns 1.12 0.01 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 2466 27,497.77 ns 186.024 ns 164.905 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 2466 31,269.44 ns 464.429 ns 387.820 ns 1.14 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 2466 27,881.42 ns 141.213 ns 132.091 ns 1.01 0.01 3,191 B
Parse Job-KGUQDB \threshold-308\corerun.exe 2466 30,732.12 ns 202.218 ns 189.155 ns 1.12 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 2466 28,331.23 ns 296.538 ns 277.381 ns 1.03 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 2466 28,304.18 ns 159.698 ns 124.682 ns 1.03 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 2466 31,702.99 ns 238.596 ns 211.509 ns 1.15 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 2476 32,075.83 ns 418.176 ns 391.163 ns 1.12 0.01 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 2476 28,743.89 ns 287.876 ns 269.280 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 2476 32,163.20 ns 411.862 ns 343.924 ns 1.12 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 2476 31,649.20 ns 258.250 ns 241.567 ns 1.10 0.01 2,925 B
Parse Job-KGUQDB \threshold-308\corerun.exe 2476 32,595.46 ns 379.406 ns 354.897 ns 1.13 0.01 2,925 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 2476 28,684.43 ns 152.782 ns 142.913 ns 1.00 0.01 3,188 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 2476 28,582.17 ns 158.176 ns 147.958 ns 0.99 0.01 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 2476 31,915.16 ns 325.739 ns 304.696 ns 1.11 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 25000 1,245,342.29 ns 13,167.604 ns 12,316.985 ns 1.01 0.01 2,926 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 25000 1,239,292.35 ns 9,980.365 ns 8,847.333 ns 1.00 0.00 2,926 B
Parse Job-XPSQQM \threshold-200\corerun.exe 25000 1,241,358.74 ns 6,959.255 ns 5,811.293 ns 1.00 0.01 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 25000 1,242,307.04 ns 11,036.003 ns 10,323.084 ns 1.00 0.01 2,926 B
Parse Job-KGUQDB \threshold-308\corerun.exe 25000 1,233,455.08 ns 8,926.373 ns 8,349.734 ns 1.00 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 25000 1,236,991.72 ns 9,447.068 ns 8,836.793 ns 1.00 0.01 2,926 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 25000 1,238,071.93 ns 12,215.321 ns 11,426.218 ns 1.00 0.01 2,926 B
Parse Job-EMOOTD \threshold-616\corerun.exe 25000 1,237,445.52 ns 14,242.437 ns 13,322.384 ns 1.00 0.01 2,926 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3000 41,579.57 ns 374.516 ns 292.397 ns 1.02 0.01 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3000 40,585.91 ns 152.930 ns 135.569 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3000 41,395.98 ns 231.905 ns 216.924 ns 1.02 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3000 42,177.11 ns 649.391 ns 607.440 ns 1.04 0.01 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3000 41,818.55 ns 664.409 ns 621.488 ns 1.03 0.01 2,925 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3000 41,695.00 ns 330.455 ns 292.939 ns 1.03 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3000 42,066.01 ns 259.452 ns 229.998 ns 1.04 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3000 42,507.69 ns 519.593 ns 486.028 ns 1.05 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3100 44,138.47 ns 621.913 ns 581.738 ns 1.00 0.02 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3100 44,030.04 ns 753.622 ns 704.938 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3100 43,733.78 ns 622.137 ns 581.948 ns 0.99 0.02 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3100 43,782.55 ns 686.472 ns 642.127 ns 0.99 0.03 2,925 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3100 44,277.29 ns 635.139 ns 594.110 ns 1.01 0.02 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3100 43,875.64 ns 502.526 ns 470.063 ns 1.00 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3100 43,654.82 ns 653.943 ns 611.699 ns 0.99 0.02 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3100 44,436.69 ns 696.144 ns 651.173 ns 1.01 0.03 2,925 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3190 44,920.78 ns 741.107 ns 693.232 ns 0.97 0.02 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3190 46,264.63 ns 582.792 ns 545.144 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3190 45,711.26 ns 543.826 ns 508.695 ns 0.99 0.01 2,927 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3190 45,720.48 ns 605.783 ns 566.649 ns 0.99 0.02 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3190 45,557.29 ns 454.296 ns 424.949 ns 0.98 0.02 2,925 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3190 45,660.31 ns 481.757 ns 450.636 ns 0.99 0.02 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3190 45,242.23 ns 703.459 ns 623.598 ns 0.98 0.02 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3190 46,610.21 ns 915.786 ns 1,017.894 ns 1.01 0.02 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3200 45,899.79 ns 644.568 ns 602.929 ns 0.97 0.01 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3200 47,093.42 ns 708.384 ns 662.623 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3200 46,128.54 ns 622.975 ns 582.732 ns 0.98 0.02 2,931 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3200 45,896.41 ns 798.760 ns 747.160 ns 0.97 0.02 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3200 45,764.53 ns 783.384 ns 732.778 ns 0.97 0.02 2,931 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3200 46,036.49 ns 790.878 ns 739.787 ns 0.98 0.03 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3200 46,453.30 ns 701.564 ns 656.243 ns 0.99 0.02 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3200 45,578.91 ns 437.396 ns 387.740 ns 0.97 0.02 2,931 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3210 45,760.47 ns 382.672 ns 357.952 ns 0.97 0.02 2,931 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3210 47,219.54 ns 933.638 ns 958.777 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3210 45,275.47 ns 604.617 ns 565.559 ns 0.96 0.03 2,927 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3210 45,396.58 ns 662.649 ns 619.842 ns 0.96 0.03 2,927 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3210 45,593.36 ns 505.674 ns 473.008 ns 0.97 0.03 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3210 46,144.32 ns 873.304 ns 816.889 ns 0.98 0.02 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3210 46,885.71 ns 676.865 ns 633.140 ns 1.00 0.03 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3210 45,237.31 ns 782.300 ns 731.764 ns 0.96 0.03 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 3300 46,003.62 ns 299.503 ns 265.502 ns 0.93 0.01 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 3300 49,350.61 ns 528.804 ns 494.644 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 3300 46,393.83 ns 354.636 ns 331.727 ns 0.94 0.01 2,931 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 3300 46,899.74 ns 470.083 ns 439.716 ns 0.95 0.01 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 3300 45,940.58 ns 413.098 ns 386.412 ns 0.93 0.01 2,931 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 3300 45,599.54 ns 447.434 ns 418.530 ns 0.92 0.01 2,931 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 3300 48,934.06 ns 717.314 ns 670.976 ns 0.99 0.02 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 3300 45,719.84 ns 495.058 ns 463.078 ns 0.93 0.01 2,931 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 4000 60,409.77 ns 1,189.593 ns 1,272.851 ns 0.86 0.03 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 4000 69,964.19 ns 969.485 ns 906.857 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 4000 59,756.88 ns 862.573 ns 806.852 ns 0.85 0.02 2,925 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 4000 57,901.70 ns 282.245 ns 235.687 ns 0.83 0.01 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 4000 58,311.05 ns 131.320 ns 116.411 ns 0.83 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 4000 58,127.65 ns 189.780 ns 168.235 ns 0.83 0.01 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 4000 68,285.37 ns 316.282 ns 295.850 ns 0.98 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 4000 58,158.31 ns 205.579 ns 192.299 ns 0.83 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 4882 92,129.97 ns 406.055 ns 379.824 ns 0.93 0.01 2,925 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 4882 99,598.25 ns 419.568 ns 371.936 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 4882 91,700.72 ns 309.033 ns 273.950 ns 0.92 0.00 2,925 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 4882 91,408.27 ns 235.709 ns 208.950 ns 0.92 0.00 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 4882 91,341.47 ns 429.112 ns 401.392 ns 0.92 0.00 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 4882 92,465.36 ns 362.318 ns 338.913 ns 0.93 0.00 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 4882 101,473.79 ns 391.057 ns 365.795 ns 1.02 0.01 3,194 B
Parse Job-EMOOTD \threshold-616\corerun.exe 4882 92,395.22 ns 525.798 ns 439.065 ns 0.93 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 4982 95,851.17 ns 552.705 ns 517.000 ns 0.91 0.01 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 4982 105,375.01 ns 428.271 ns 379.651 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 4982 95,321.02 ns 298.252 ns 278.985 ns 0.90 0.00 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 4982 96,218.30 ns 390.058 ns 345.776 ns 0.91 0.00 2,926 B
Parse Job-KGUQDB \threshold-308\corerun.exe 4982 97,355.89 ns 506.387 ns 473.675 ns 0.92 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 4982 96,689.38 ns 387.189 ns 362.177 ns 0.92 0.00 2,926 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 4982 96,624.11 ns 360.319 ns 337.043 ns 0.92 0.00 2,929 B
Parse Job-EMOOTD \threshold-616\corerun.exe 4982 96,034.83 ns 419.141 ns 392.065 ns 0.91 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 500 1,922.27 ns 8.014 ns 7.496 ns 0.95 0.00 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 500 2,020.99 ns 11.359 ns 10.626 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 500 2,424.48 ns 15.145 ns 14.167 ns 1.20 0.01 2,926 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 500 1,936.94 ns 10.357 ns 8.648 ns 0.96 0.01 3,191 B
Parse Job-KGUQDB \threshold-308\corerun.exe 500 2,408.43 ns 15.133 ns 14.155 ns 1.19 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 500 1,926.74 ns 9.225 ns 8.629 ns 0.95 0.01 3,188 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 500 2,024.09 ns 7.141 ns 6.330 ns 1.00 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 500 2,005.87 ns 9.215 ns 8.620 ns 0.99 0.01 3,191 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 50000 3,572,937.92 ns 12,419.934 ns 11,617.614 ns 0.99 0.00 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 50000 3,590,195.45 ns 9,636.735 ns 8,542.715 ns 1.00 0.00 2,931 B
Parse Job-XPSQQM \threshold-200\corerun.exe 50000 3,604,425.42 ns 12,173.221 ns 11,386.838 ns 1.00 0.00 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 50000 3,627,130.91 ns 17,069.917 ns 15,967.211 ns 1.01 0.01 2,931 B
Parse Job-KGUQDB \threshold-308\corerun.exe 50000 3,610,770.73 ns 14,022.926 ns 13,117.054 ns 1.01 0.01 2,931 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 50000 3,606,370.94 ns 16,162.860 ns 15,118.749 ns 1.00 0.00 2,931 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 50000 3,597,071.06 ns 6,055.809 ns 5,056.875 ns 1.00 0.00 2,931 B
Parse Job-EMOOTD \threshold-616\corerun.exe 50000 3,588,517.61 ns 15,084.861 ns 13,372.336 ns 1.00 0.00 2,931 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 606 2,673.65 ns 9.829 ns 8.713 ns 1.05 0.01 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 606 2,544.31 ns 10.244 ns 9.583 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 606 3,530.23 ns 12.915 ns 12.081 ns 1.39 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 606 2,541.89 ns 12.190 ns 11.402 ns 1.00 0.01 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 606 3,606.61 ns 18.699 ns 17.491 ns 1.42 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 606 2,552.82 ns 12.588 ns 11.775 ns 1.00 0.01 3,191 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 606 2,667.62 ns 19.648 ns 18.379 ns 1.05 0.01 3,191 B
Parse Job-EMOOTD \threshold-616\corerun.exe 606 2,587.45 ns 14.697 ns 13.748 ns 1.02 0.01 3,191 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 616 2,645.71 ns 7.668 ns 7.173 ns 1.03 0.00 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 616 2,573.95 ns 4.756 ns 3.972 ns 1.00 0.00 3,188 B
Parse Job-XPSQQM \threshold-200\corerun.exe 616 3,626.34 ns 15.038 ns 13.331 ns 1.41 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 616 2,720.23 ns 11.648 ns 10.896 ns 1.06 0.00 3,191 B
Parse Job-KGUQDB \threshold-308\corerun.exe 616 3,688.62 ns 15.496 ns 14.495 ns 1.43 0.01 2,929 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 616 2,605.68 ns 14.471 ns 13.536 ns 1.01 0.01 3,188 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 616 2,664.84 ns 17.832 ns 14.891 ns 1.04 0.01 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 616 2,598.78 ns 15.398 ns 14.404 ns 1.01 0.01 3,191 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 626 2,646.08 ns 11.364 ns 10.630 ns 0.95 0.00 3,191 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 626 2,775.41 ns 7.895 ns 6.593 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 626 3,802.86 ns 22.221 ns 19.698 ns 1.37 0.01 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 626 2,894.32 ns 46.959 ns 43.925 ns 1.04 0.02 3,188 B
Parse Job-KGUQDB \threshold-308\corerun.exe 626 3,700.36 ns 20.785 ns 17.356 ns 1.33 0.01 2,926 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 626 2,774.55 ns 10.192 ns 9.035 ns 1.00 0.00 3,188 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 626 2,645.78 ns 12.794 ns 11.967 ns 0.95 0.00 3,188 B
Parse Job-EMOOTD \threshold-616\corerun.exe 626 3,730.61 ns 14.709 ns 13.039 ns 1.34 0.01 2,929 B
Parse Job-JWHCHB \threshold-1233\corerun.exe 7500 165,031.43 ns 469.389 ns 439.067 ns 0.72 0.00 2,929 B
Parse Job-HSPWLR \threshold-20000\corerun.exe 7500 230,330.41 ns 1,049.541 ns 930.391 ns 1.00 0.00 3,191 B
Parse Job-XPSQQM \threshold-200\corerun.exe 7500 164,063.06 ns 552.112 ns 489.433 ns 0.71 0.00 2,929 B
Parse Job-FPLNZJ \threshold-2466\corerun.exe 7500 163,309.05 ns 945.082 ns 737.857 ns 0.71 0.00 2,929 B
Parse Job-KGUQDB \threshold-308\corerun.exe 7500 173,182.86 ns 3,243.232 ns 6,091.575 ns 0.75 0.03 2,926 B
Parse Job-CJQMQG \threshold-3200\corerun.exe 7500 167,976.12 ns 2,058.915 ns 1,825.175 ns 0.73 0.01 2,929 B
Parse Job-KVUNWZ \threshold-4932\corerun.exe 7500 169,033.89 ns 3,114.871 ns 2,913.652 ns 0.73 0.01 2,929 B
Parse Job-EMOOTD \threshold-616\corerun.exe 7500 164,557.64 ns 1,026.810 ns 960.478 ns 0.71 0.00 2,929 B

@tannergooding
Copy link
Member

Looking at this, the numbers are all fairly close. We will want to measure on some other hardware as well, but I think that 308 or 1233 is probably the "right" choice here.

Either covers the majority of most common inputs and allows for the less naive algorithm to be used for large/uncommon inputs.

@tannergooding
Copy link
Member

Thanks for the contribution! Going to merge this and wait for some more numbers in the official perf benchmarks.

The numbers looked roughly similar to what you gave above on my Zen4 based box and this is a trivial 1-liner we can revert if needed.

@tannergooding tannergooding merged commit 678ae31 into dotnet:main Jan 29, 2024
106 of 111 checks passed
@kzrnm kzrnm deleted the BigIntegerParseThreshold branch January 29, 2024 16:46
@github-actions github-actions bot locked and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants