Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Rational Type Performance

Note that these tests are carefully designed to test performance of the underlying algorithms and not memory allocation or variable copying. As usual, performance results should be taken with a healthy dose of scepticism, and real-world performance may vary widely depending upon the specifics of the program. In each table relative times are given first, with the best performer given a score of 1. Total actual times are given in brackets, measured in seconds for 500000 operations.

Table 1.76. Operator *

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.00025 (0.797425s)

1.97726 (2.96998s)

1.86844 (6.73224s)

1.96608 (14.4259s)

mpq_rational

1 (0.398662s)

1 (1.50207s)

1 (3.60314s)

1 (7.3374s)


Table 1.77. Operator *(int)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.88073 (0.0637195s)

1.93184 (0.0917847s)

2.15609 (0.118274s)

2.4236 (0.218283s)

mpq_rational

1 (0.0338803s)

1 (0.0475114s)

1 (0.0548556s)

1 (0.0900656s)


Table 1.78. Operator *(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.60877 (0.161844s)

2.33429 (0.240069s)

1.8835 (0.298935s)

2.70338 (0.448194s)

mpq_rational

1 (0.100601s)

1 (0.102844s)

1 (0.158713s)

1 (0.16579s)


Table 1.79. Operator *(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.97503 (0.408791s)

2.42069 (0.600225s)

2.65138 (0.803009s)

4.65673 (1.54645s)

mpq_rational

1 (0.20698s)

1 (0.247956s)

1 (0.302865s)

1 (0.332089s)


Table 1.80. Operator *=(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.97207 (0.211848s)

2.18482 (0.226179s)

2.43682 (0.319695s)

2.69933 (0.485819s)

mpq_rational

1 (0.107424s)

1 (0.103523s)

1 (0.131194s)

1 (0.179978s)


Table 1.81. Operator *=(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.95211 (0.40255s)

2.60942 (0.629302s)

2.83854 (0.8029s)

4.34054 (1.37083s)

mpq_rational

1 (0.206213s)

1 (0.241165s)

1 (0.282857s)

1 (0.31582s)


Table 1.82. Operator +

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.20364 (0.415006s)

1.97574 (1.53458s)

1.75945 (3.41194s)

2.11634 (8.04044s)

mpq_rational

1 (0.188327s)

1 (0.776716s)

1 (1.93921s)

1 (3.79923s)


Table 1.83. Operator +(int)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.06836 (0.0177811s)

1.80334 (0.0183744s)

1.38442 (0.020452s)

1.81894 (0.0449351s)

mpq_rational

1 (0.00859669s)

1 (0.0101891s)

1 (0.014773s)

1 (0.024704s)


Table 1.84. Operator +(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.07187 (0.0177151s)

2.3005 (0.0241089s)

1.81397 (0.0297836s)

1.72202 (0.046594s)

mpq_rational

1 (0.0085503s)

1 (0.0104799s)

1 (0.016419s)

1 (0.0270577s)


Table 1.85. Operator +(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.2805 (0.0265647s)

1.59353 (0.0391054s)

1.26613 (0.044067s)

1.95307 (0.105801s)

mpq_rational

1 (0.0207456s)

1 (0.0245401s)

1 (0.0348044s)

1 (0.0541719s)


Table 1.86. Operator +=(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

7.29749 (0.0565983s)

3.77253 (0.0371419s)

2.72128 (0.0556987s)

2.01495 (0.0662456s)

mpq_rational

1 (0.00775585s)

1 (0.00984535s)

1 (0.0204678s)

1 (0.032877s)


Table 1.87. Operator +=(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.92025 (0.0335896s)

2.08321 (0.0422867s)

1.587 (0.0564267s)

1.85357 (0.0840696s)

mpq_rational

1 (0.0174923s)

1 (0.0202988s)

1 (0.0355556s)

1 (0.0453556s)


Table 1.88. Operator -

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.38126 (0.471759s)

1.92631 (1.52484s)

1.76181 (3.49648s)

2.03462 (7.71926s)

mpq_rational

1 (0.198113s)

1 (0.791584s)

1 (1.98459s)

1 (3.79396s)


Table 1.89. Operator -(int)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.44447 (0.0292894s)

2.54602 (0.0346718s)

1.4869 (0.035503s)

1.95344 (0.0577029s)

mpq_rational

1 (0.0119819s)

1 (0.013618s)

1 (0.0238773s)

1 (0.0295391s)


Table 1.90. Operator -(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.93654 (0.0296698s)

4.23087 (0.0496956s)

1.68041 (0.0461985s)

1.4455 (0.0581714s)

mpq_rational

1 (0.0101037s)

1 (0.0117459s)

1 (0.0274924s)

1 (0.040243s)


Table 1.91. Operator -(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.69242 (0.0408789s)

1.5205 (0.0467416s)

1.31525 (0.0548939s)

2.16115 (0.103471s)

mpq_rational

1 (0.0241541s)

1 (0.030741s)

1 (0.0417365s)

1 (0.0478777s)


Table 1.92. Operator -=(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

3.69509 (0.0366534s)

3.7306 (0.0439181s)

1.8352 (0.0491612s)

1.86662 (0.071761s)

mpq_rational

1 (0.00991947s)

1 (0.0117724s)

1 (0.0267879s)

1 (0.0384444s)


Table 1.93. Operator -=(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.76299 (0.0421283s)

2.03803 (0.0490152s)

1.84864 (0.053198s)

2.10533 (0.0881228s)

mpq_rational

1 (0.023896s)

1 (0.0240502s)

1 (0.0287769s)

1 (0.041857s)


Table 1.94. Operator /

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

2.03433 (2.28881s)

2.24309 (6.34454s)

2.1203 (13.2036s)

2.36142 (29.3236s)

mpq_rational

1 (1.12509s)

1 (2.82848s)

1 (6.22726s)

1 (12.4178s)


Table 1.95. Operator /(int)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1 (0.035134s)

1.08556 (0.0774619s)

1.08797 (0.104628s)

1.29134 (0.207067s)

mpq_rational

1.85049 (0.0650149s)

1 (0.0713565s)

1 (0.0961679s)

1 (0.16035s)


Table 1.96. Operator /(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.31397 (0.170727s)

1.63747 (0.216019s)

1.68581 (0.292536s)

1.76695 (0.435259s)

mpq_rational

1 (0.129932s)

1 (0.131923s)

1 (0.173528s)

1 (0.246334s)


Table 1.97. Operator /(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.82473 (0.431612s)

2.20261 (0.596248s)

2.45848 (0.809662s)

3.88675 (1.38001s)

mpq_rational

1 (0.236534s)

1 (0.270701s)

1 (0.329335s)

1 (0.355055s)


Table 1.98. Operator /=(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.58868 (0.216252s)

1.71288 (0.235781s)

1.78218 (0.314161s)

1.98715 (0.460033s)

mpq_rational

1 (0.136121s)

1 (0.137652s)

1 (0.176279s)

1 (0.231505s)


Table 1.99. Operator /=(value_type)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1.72896 (0.40369s)

2.55949 (0.689514s)

2.4929 (0.832288s)

3.51238 (1.37478s)

mpq_rational

1 (0.233487s)

1 (0.269395s)

1 (0.333863s)

1 (0.391409s)


Table 1.100. Operator construct

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1 (0.0135822s)

1 (0.00935293s)

1 (0.0083784s)

1 (0.00962697s)

mpq_rational

1.44264 (0.0195942s)

2.18249 (0.0204126s)

2.64725 (0.0221797s)

2.87767 (0.0277033s)


Table 1.101. Operator construct(unsigned long long)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1 (0.00806026s)

1 (0.00960336s)

1 (0.00769898s)

1 (0.0176689s)

mpq_rational

4.87225 (0.0392716s)

5.91987 (0.0568506s)

9.03811 (0.0695842s)

3.68339 (0.0650815s)


Table 1.102. Operator construct(unsigned)

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

1 (0.00672081s)

1 (0.0064826s)

1 (0.00618635s)

1 (0.00923644s)

mpq_rational

6.47138 (0.0434929s)

7.48645 (0.0485316s)

8.2942 (0.0513108s)

5.77363 (0.0533278s)


Table 1.103. Operator str

Backend

128 Bits

256 Bits

512 Bits

1024 Bits

cpp_rational

6.17439 (0.00168424s)

7.6748 (0.0033367s)

6.38435 (0.00662873s)

9.07696 (0.0174979s)

mpq_rational

1 (0.000272779s)

1 (0.000434761s)

1 (0.00103828s)

1 (0.00192772s)


Table 1.104. Platform Details

Version

Compiler

GNU C++ version 10.3.0

GMP

6.2.0

MPFR

262146

Boost

107800

Run date

Sep 30 2021



PrevUpHomeNext