Benchmarks

This section describes a range of performance benchmarks that have been run comparing this library with the standard library, and how to run your own benchmarks if required.

The values in the ratio column are how many times longer running a specific operation takes in comparison to the same operation with a double.

On nearly all platforms, there is hardware support for binary floating point math, so we are comparing hardware to software runtimes; Decimal will be slower
Both the results from Intel and GCC types are from very close, but not identical benchmark routines since they are written in C instead of C++. We assume they are close enough, and the differences between the C and C++ compilers are small enough, for fair comparison

How to run the Benchmarks

To run the benchmarks yourself, navigate to the test folder and define BOOST_DECIMAL_RUN_BENCHMARKS when running the tests. An example on Linux with b2: ../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_DECIMAL_RUN_BENCHMARKS benchmarks -a release, or ../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_DECIMAL_RUN_BENCHMARKS=1,BOOST_DECIMAL_BENCHMARK_CHARCONV=1 benchmarks -a release to also run the <charconv> benchmarks

To run the GCC benchmarks you can use the following command: gcc benchmark_libdfp.c -O3 -std=c17 followed by: ./a.out

To run the Intel benchmarks you will need both the Intel Compiler, and the library. You can the use the following command: icx benchmark_libbid.c -O3 $PATH_TO_LIBBID/libbid.a -std=c17 followed by: ./a.out You can also use gcc instead of icx. On windows the command is similarly: cl benchmark_libbid.c /O2 /std:c17 ..\PATH_TO_LIBBID\cl000libbid.lib, followed by: .\benchmark_libbid.exe.

The Intel benchmarks can only be run on one of their supported architectures: IA-32, IA-64, and Intel x64

Methodology

Comparisons

The benchmark for comparisons generates a random vector containing 20,000,000 elements and does operations >, >=, <, <=, ==, and != between vec[i] and vec[i + 1]. This is repeated 5 times to generate stable results.

Basic Mathematical Operations

The benchmark for these operations generates a random vector containing 20 million elements and does operations +, -, *, / between vec[i] and vec[i + 1]. This is repeated five times to generate stable results.

<charconv>

Parsing and serializing number exactly is one of the key features of decimal floating point types, so we must compare the performance of <charconv>. For all the following the results compare we compare against STL provided <charconv> for 20 million conversions. Since <charconv> is fully implemented in software for each type the performance gap between built-in float and double vs decimal32_t and decimal64_t is significantly smaller (or the decimal performance is better) than the hardware vs. software performance gap seen above for basic operations.

To run these benchmarks yourself, you will need a compiler with complete implementation of <charconv> and to run the benchmarks under C++17 or higher. At the time of writing, this is limited to:

  • GCC 11 or newer

  • MSVC 19.24 or newer

These benchmarks are automatically disabled if your compiler does not provide feature complete <charconv> or if the language standard is set to C++14.

x64 Linux

Run using an Intel i9-11900k chipset running Ubuntu 24.04 and Intel oneAPI compiler 2025.3.3 or GCC 13.4.0.

Comparisons

Intel Compiler:

Type

Runtime (us)

Ratio to double

float

70,801

0.499

double

141,854

1.000

decimal32_t

1,322,218

9.321

decimal64_t

1,599,987

11.279

decimal128_t

3,951,400

27.855

decimal_fast32_t

537,268

3.787

decimal_fast64_t

556,455

3.923

decimal_fast128_t

667,681

4.707

Intel BID_UINT32

3,680,493

25.946

Intel BID_UINT64

5,714,482

40.284

Intel BID_UINT128

5,853,596

41.265

GCC:

Type

Runtime (us)

Ratio to double

float

55,070

0.952

double

57,870

1.000

decimal32_t

1,103,116

19.062

decimal64_t

1,090,026

18.836

decimal128_t

3,772,309

65.186

decimal_fast32_t

465,000

8.035

decimal_fast64_t

513,587

8.875

decimal_fast128_t

444,145

7.675

GCC _Decimal32

831,820

14.374

GCC _Decimal64

475,605

8.219

GCC _Decimal128

872,026

15.069

Intel BID_UINT32

3,658,360

63.217

Intel BID_UINT64

5,452,325

94.217

Intel BID_UINT128

5,705,342

98.589

Addition

Intel Compiler:

Type

Runtime (us)

Ratio to double

float

76,312

1.105

double

69,075

1.000

decimal32_t

1,238,019

17.923

decimal64_t

1,087,951

15.750

decimal128_t

2,381,956

34.484

decimal_fast32_t

944,208

13.669

decimal_fast64_t

754,414

10.922

decimal_fast128_t

767,338

11.109

Intel BID_UINT32

2,895,250

41.915

Intel BID_UINT64

3,477,761

50.348

Intel BID_UINT128

2,587,966

37.466

GCC:

Type

Runtime (us)

Ratio to double

float

72,939

1.166

double

62,541

1.000

decimal32_t

1,225,447

19.594

decimal64_t

1,257,515

20.107

decimal128_t

2,085,250

33.342

decimal_fast32_t

771,283

12.332

decimal_fast64_t

1,064,025

17.013

decimal_fast128_t

926,772

14.819

GCC _Decimal32

2,894,703

46.285

GCC _Decimal64

2,100,094

33.579

GCC _Decimal128

3,264,420

52.196

Intel BID_UINT32

2,574,559

41.166

Intel BID_UINT64

3,379,104

54.030

Intel BID_UINT128

2,509,923

40.132

Subtraction

Intel Compiler:

Type

Runtime (us)

Ratio to double

float

76,299

1.104

double

69,112

1.000

decimal32_t

1,274,392

18.440

decimal64_t

1,181,406

17.094

decimal128_t

2,343,671

33.911

decimal_fast32_t

1,003,326

14.517

decimal_fast64_t

823,770

11.919

decimal_fast128_t

945,118

13.675

Intel BID_UINT32

3,853,532

55.758

Intel BID_UINT64

3,550,643

51.375

Intel BID_UINT128

3,186,584

46.108

GCC:

Type

Runtime (us)

Ratio to double

float

267,529

0.976

double

274,107

1.000

decimal32_t

1,228,320

4.481

decimal64_t

1,313,266

4.791

decimal128_t

2,234,926

8.153

decimal_fast32_t

790,531

2.884

decimal_fast64_t

1,166,909

4.257

decimal_fast128_t

1,445,687

5.274

GCC _Decimal32

1,972,600

7.196

GCC _Decimal64

1,313,261

4.791

GCC _Decimal128

3,084,987

11.255

Intel BID_UINT32

3,539,123

12.911

Intel BID_UINT64

3,522,244

12.850

Intel BID_UINT128

3,042,150

11.098

Multiplication

Intel Compiler:

Type

Runtime (us)

Ratio to double

float

77,440

1.122

double

68,993

1.000

decimal32_t

2,142,304

31.051

decimal64_t

2,378,675

34.477

decimal128_t

6,705,642

97.193

decimal_fast32_t

1,616,807

23.434

decimal_fast64_t

1,934,743

28.043

decimal_fast128_t

5,788,000

83.893

Intel BID_UINT32

2,719,047

39.410

Intel BID_UINT64

5,078,522

73.609

Intel BID_UINT128

21,265,835

308.232

GCC:

Type

Runtime (us)

Ratio to double

float

72,857

1.165

double

62,531

1.000

decimal32_t

2,112,818

33.788

decimal64_t

2,528,577

40.437

decimal128_t

7,966,781

127.405

decimal_fast32_t

1,130,499

18.079

decimal_fast64_t

2,312,590

36.983

decimal_fast128_t

8,116,908

129.806

GCC _Decimal32

2,576,432

41.202

GCC _Decimal64

2,462,813

39.385

GCC _Decimal128

6,683,052

106.876

Intel BID_UINT32

2,635,154

42.142

Intel BID_UINT64

4,973,224

79.532

Intel BID_UINT128

21,352,000

341.463

Division

Intel Compiler:

Type

Runtime (us)

Ratio to double

float

99,024

0.943

double

105,042

1.000

decimal32_t

2,416,706

23.007

decimal64_t

2,516,984

23.962

decimal128_t

5,995,607

57.078

decimal_fast32_t

1,708,582

16.266

decimal_fast64_t

1,990,538

18.950

decimal_fast128_t

4,335,834

41.277

Intel BID_UINT32

3,600,610

34.278

Intel BID_UINT64

5,739,738

54.642

Intel BID_UINT128

15,019,593

142.987

GCC:

Type

Runtime (us)

Ratio to double

float

58,777

0.761

double

77,196

1.000

decimal32_t

2,079,584

26.939

decimal64_t

2,477,436

32.093

decimal128_t

5,854,061

75.834

decimal_fast32_t

1,718,838

22.266

decimal_fast64_t

1,724,535

22.340

decimal_fast128_t

4,442,123

57.543

GCC _Decimal32

4,868,534

63.067

GCC _Decimal64

2,904,760

37.628

GCC _Decimal128

9,906,049

128.323

Intel BID_UINT32

3,356,191

43.476

Intel BID_UINT64

5,745,255

74.424

Intel BID_UINT128

14,918,326

193.253

from_chars

General Format

Type

Runtime (us)

Ratio to double

float

2,437,788

0.917

double

2,657,378

1.000

decimal32_t

3,131,251

1.178

decimal64_t

4,291,891

1.615

decimal128_t

9,911,474

3.730

decimal_fast32_t

4,737,095

1.783

decimal_fast64_t

4,404,334

1.657

decimal_fast128_t

10,414,943

3.919

Scientific Format

Type

Runtime (us)

Ratio to double

float

2,506,008

0.954

double

2,625,702

1.000

decimal32_t

3,008,653

1.146

decimal64_t

4,180,192

1.592

decimal128_t

9,712,229

3.699

decimal_fast32_t

4,142,588

1.578

decimal_fast64_t

4,118,461

1.569

decimal_fast128_t

8,772,097

3.341

to_chars

General Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

2,920,036

0.850

double

3,436,919

1.000

decimal32_t

4,136,631

1.204

decimal64_t

4,318,996

1.257

decimal128_t

14,624,180

4.255

decimal_fast32_t

4,752,219

1.383

decimal_fast64_t

4,382,014

1.275

decimal_fast128_t

17,350,588

5.048

General Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

5,541,073

0.969

double

5,716,626

1.000

decimal32_t

3,527,433

0.617

decimal64_t

4,125,772

0.722

decimal128_t

6,967,211

1.219

decimal_fast32_t

3,654,219

0.639

decimal_fast64_t

3,386,125

0.592

decimal_fast128_t

6,018,439

1.053

Scientific Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

2,841,569

0.827

double

3,437,387

1.000

decimal32_t

2,564,053

0.750

decimal64_t

2,856,944

0.831

decimal128_t

12,147,039

3.534

decimal_fast32_t

2,878,507

0.837

decimal_fast64_t

2,933,273

0.853

decimal_fast128_t

15,010,374

4.367

Scientific Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

4,896,523

0.958

double

5,112,924

1.000

decimal32_t

2,542,237

0.497

decimal64_t

3,119,552

0.610

decimal128_t

4,811,741

0.941

decimal_fast32_t

2,890,023

0.565

decimal_fast64_t

2,956,466

0.578

decimal_fast128_t

5,476,431

1.071

x64 Windows

Run using an Intel i9-11900k chipset running Windows 11 and Visual Studio 17.14.10

Comparisons

Type

Runtime (us)

Ratio to double

float

191,653

1.028

double

186,424

1.000

decimal32_t

2,391,863

12.830

decimal64_t

2,491,239

13.363

decimal128_t

16,643,031

89.275

decimal_fast32_t

872,997

4.682

decimal_fast64_t

793,997

4.259

decimal_fast128_t

801,708

4.300

Intel BID_UINT32

4,372,973

23.457

Intel BID_UINT64

9,345,300

50.129

Intel BID_UINT128

11,504,914

61.714

Addition

Type

Runtime (us)

Ratio to double

float

76,777

0.961

double

79,897

1.000

decimal32_t

2,902,356

36.326

decimal64_t

3,569,820

44.680

decimal128_t

12,075,529

151.139

decimal_fast32_t

1,940,333

24.285

decimal_fast64_t

3,064,073

38.350

decimal_fast128_t

3,109,101

38.914

Intel BID_UINT32

4,967,728

62.177

Intel BID_UINT64

6,268,077

78.452

Intel BID_UINT128

4,847,330

60.670

Subtraction

Type

Runtime (us)

Ratio to double

float

336,960

1.042

double

323,282

1.000

decimal32_t

3,040,167

9.404

decimal64_t

3,617,843

11.191

decimal128_t

12,325,962

38.128

decimal_fast32_t

2,313,234

7.155

decimal_fast64_t

2,935,476

9.080

decimal_fast128_t

2,963,570

9.167

Intel BID_UINT32

4,603,462

14.240

Intel BID_UINT64

5,627,305

17.407

Intel BID_UINT128

5,824,263

18.016

Multiplication

Type

Runtime (us)

Ratio to double

float

78,634

1.000

double

78,649

1.000

decimal32_t

2,636,784

33.526

decimal64_t

3,861,139

49.093

decimal128_t

11,349,378

144.304

decimal_fast32_t

2,688,661

34.186

decimal_fast64_t

3,504,172

44.554

decimal_fast128_t

9,236,110

117.434

Intel BID_UINT32

3,833,363

48.740

Intel BID_UINT64

11,671,369

148.398

Intel BID_UINT128

62,036,577

788.778

Division

Type

Runtime (us)

Ratio to double

float

83,566

0.936

double

89,317

1.000

decimal32_t

3,048,254

34.128

decimal64_t

3,282,819

36.755

decimal128_t

16,648,799

186.401

decimal_fast32_t

2,059,743

23.061

decimal_fast64_t

5,105,018

57.156

decimal_fast128_t

11,587,763

129,737

Intel BID_UINT32

5,037,576

46.401

Intel BID_UINT64

8,768,259

98.170

Intel BID_UINT128

38,519,644

431.269

from_chars

General Format

Type

Runtime (us)

Ratio to double

float

7,892,780

0.457

double

17,282,516

1.000

decimal32_t

3,544,166

0.205

decimal64_t

5,095,337

0.295

decimal128_t

18,972,286

1.098

decimal_fast32_t

5,182,044

0.300

decimal_fast64_t

6,344,823

0.367

decimal_fast128_t

34,476,545

1.995

Scientific Format

Type

Runtime (us)

Ratio to double

float

7,839,980

0.454

double

17,282,516

1.000

decimal32_t

3,393,317

0.196

decimal64_t

4,924,720

0.285

decimal128_t

29,240,187

1.692

decimal_fast32_t

5,092,334

0.295

decimal_fast64_t

6,341,230

0.367

decimal_fast128_t

34,519,610

1.997

to_chars

General Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

3,181,029

0.826

double

3,852,857

1.000

decimal32_t

5,242,934

1.361

decimal64_t

5,586,541

1.450

decimal128_t

13,955,214

3.622

decimal_fast32_t

6,053,804

1.571

decimal_fast64_t

7,957,278

2.065

decimal_fast128_t

20,202,107

5.243

General Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

6,111,231

0.949

double

6,433,885

1.000

decimal32_t

4,605,311

0.716

decimal64_t

4,742,497

0.737

decimal128_t

12,372,901

1.923

decimal_fast32_t

4,716,827

0.733

decimal_fast64_t

4,861,975

0.756

decimal_fast128_t

10,779,778

1.675

Scientific Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

3,107,509

0.773

double

4,020,767

1.000

decimal32_t

3,428,517

0.853

decimal64_t

4,095,802

1.019

decimal128_t

11,577,791

2.879

decimal_fast32_t

3,375,975

0.840

decimal_fast64_t

4,427,563

1.101

decimal_fast128_t

13,581,654

3.378

Scientific Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

4,938,623

0.930

double

5,309,818

1.000

decimal32_t

3,435,843

0.647

decimal64_t

3,682,980

0.694

decimal128_t

9,223,227

1.737

decimal_fast32_t

3,379,702

0.637

decimal_fast64_t

3,892,990

0.733

decimal_fast128_t

10,158,657

1.913

ARM64 macOS

Run using a Macbook pro with M4 Max chipset running macOS Tahoe 26.5.1 and homebrew Clang 22.1.7

Comparisons

Type

Runtime (us)

Ratio to double

float

67,936

1.536

double

44,239

1.000

decimal32_t

998,053

22.560

decimal64_t

958,425

21.665

decimal128_t

2,055,981

46.474

decimal_fast32_t

506,597

11.451

decimal_fast64_t

473,861

10.711

decimal_fast128_t

441,387

9.977

Addition

Type

Runtime (us)

Ratio to double

float

12,488

0.994

double

12,561

1.000

decimal32_t

1,111,870

88.518

decimal64_t

825,194

65.695

decimal128_t

1,439,508

114.601

decimal_fast32_t

687,518

54.734

decimal_fast64_t

610,775

48.625

decimal_fast128_t

693,826

55.237

Subtraction

Type

Runtime (us)

Ratio to double

float

12,655

1.001

double

12,645

1.000

decimal32_t

1,151,474

91.062

decimal64_t

910,530

72.007

decimal128_t

1,537,309

121.574

decimal_fast32_t

755,153

59.719

decimal_fast64_t

702,725

55.573

decimal_fast128_t

789,072

62.402

Multiplication

Type

Runtime (us)

Ratio to double

float

12,866

1.000

double

12,869

1.000

decimal32_t

2,104,935

163.566

decimal64_t

2,157,113

167.621

decimal128_t

5,183,487

402.789

decimal_fast32_t

1,536,569

119.401

decimal_fast64_t

1,934,438

150.318

decimal_fast128_t

4,762,463

370.072

Division

Type

Runtime (us)

Ratio to double

float

13,501

0.750

double

18,001

1.000

decimal32_t

2,210,859

122.819

decimal64_t

2,495,550

138.634

decimal128_t

8,639,540

479.948

decimal_fast32_t

1,557,445

86.520

decimal_fast64_t

2,394,632

133.028

decimal_fast128_t

7,662,160

425.652

from_chars

General Format

Type

Runtime (us)

Ratio to double

float

1,882,825

0.990

double

1,901,380

1.000

decimal32_t

3,427,654

1.803

decimal64_t

5,364,564

2.821

decimal128_t

11,752,375

6.181

decimal_fast32_t

4,339,550

2.282

decimal_fast64_t

6,647,959

3.496

decimal_fast128_t

14,010,588

7.369

Scientific Format

Type

Runtime (us)

Ratio to double

float

1,939,033

1.010

double

1,919,671

1.000

decimal32_t

3,411,016

1.777

decimal64_t

5,278,214

2.750

decimal128_t

11,479,704

5.980

decimal_fast32_t

4,299,497

2.240

decimal_fast64_t

6,287,638

3.275

decimal_fast128_t

9,856,122

5.134

to_chars

General Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

2,223,891

0.882

double

2,520,203

1.000

decimal32_t

2,983,523

1.184

decimal64_t

3,348,702

1.329

decimal128_t

8,899,289

3.531

decimal_fast32_t

3,383,567

1.343

decimal_fast64_t

3,436,470

1.364

decimal_fast128_t

12,509,443

4.964

General Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

4,664,538

0.948

double

4,915,699

1.000

decimal32_t

2,570,339

0.523

decimal64_t

3,309,343

0.673

decimal128_t

5,962,030

1.212

decimal_fast32_t

2,213,792

0.450

decimal_fast64_t

3,067,584

0.624

decimal_fast128_t

6,006,157

1.222

Scientific Format Shortest Precision

Type

Runtime (us)

Ratio to double

float

2,119,538

0.848

double

2,500,900

1.000

decimal32_t

1,757,416

0.703

decimal64_t

2,187,911

0.875

decimal128_t

6,976,380

2.790

decimal_fast32_t

1,739,069

0.695

decimal_fast64_t

2,060,848

0.824

decimal_fast128_t

12,509,443

5.002

Scientific Format 6 digits Precision

Type

Runtime (us)

Ratio to double

float

4,157,977

0.933

double

4,457,878

1.000

decimal32_t

1,764,018

0.395

decimal64_t

2,625,621

0.589

decimal128_t

4,060,487

0.911

decimal_fast32_t

1,728,473

0.388

decimal_fast64_t

2,734,955

0.614

decimal_fast128_t

5,300,774

1.189

ARM64 Windows

Run on the GitHub Actions windows-11-arm runner using MSVC in release mode.

Comparisons

Type

Runtime (us)

Ratio to double

float

182,667

1.012

double

180,555

1.000

decimal32_t

1,679,312

9.301

decimal64_t

2,203,320

12.203

decimal128_t

8,833,555

48.924

decimal_fast32_t

872,493

4.832

decimal_fast64_t

891,568

4.938

decimal_fast128_t

907,563

5.027

Addition

Type

Runtime (us)

Ratio to double

float

60,279

0.941

double

64,051

1.000

decimal32_t

2,209,244

34.492

decimal64_t

2,231,636

34.842

decimal128_t

5,480,362

85.562

decimal_fast32_t

1,502,684

23.461

decimal_fast64_t

1,982,389

30.950

decimal_fast128_t

2,889,333

45.110

Subtraction

Type

Runtime (us)

Ratio to double

float

55,587

0.918

double

60,552

1.000

decimal32_t

2,346,070

38.745

decimal64_t

2,458,995

40.610

decimal128_t

5,268,604

87.010

decimal_fast32_t

1,879,880

31.046

decimal_fast64_t

2,346,222

38.747

decimal_fast128_t

3,237,777

53.471

Multiplication

Type

Runtime (us)

Ratio to double

float

56,447

0.914

double

61,774

1.000

decimal32_t

3,276,537

53.041

decimal64_t

4,325,985

70.029

decimal128_t

15,726,575

254.582

decimal_fast32_t

2,313,991

37.459

decimal_fast64_t

3,821,815

61.868

decimal_fast128_t

15,496,341

250.855

Division

Type

Runtime (us)

Ratio to double

float

56,701

0.381

double

149,002

1.000

decimal32_t

3,664,152

24.591

decimal64_t

7,224,334

48.485

decimal128_t

16,818,955

112.877

decimal_fast32_t

2,750,313

18.458

decimal_fast64_t

6,758,148

45.356

decimal_fast128_t

15,086,240

101.249