<!--script src="https://raw.githubusercontent.com/iriscouch/bigdecimal.js/v0.6.1/lib/bigdecimal.js"></script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.0.2/bignumber.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/big.js/6.0.3/big.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.2.1/decimal.min.js"></script>
<!--script src="https://raw.githubusercontent.com/infusion/Fraction.js/v4.0.12/fraction.min.js"></script-->
var a = 10000000000000000001.11;
var b = 100000000000000000010.21;
((a + b) * b).toString();
var a = 10000000000000000001.11;
var b = 10000000000000000001.21;
((a + b) * b).toFixed(9);
var a = new Decimal("10000000000000000001.11");
var b = new Decimal("10000000000000000001.21");
a.plus(b).times(b).toString();
var a = new Big("10000000000000000001.11");
var b = new Big("10000000000000000001.21");
a.plus(b).mul(b).toString();
var a = new BigNumber("10000000000000000001.11");
var b = new BigNumber("10000000000000000001.21");
a.plus(b).multipliedBy(b).toString();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native | |
Native + toFixed | |
decimal.js | |
big.js | |
bignumber.js |
Test name | Executions per second |
---|---|
Native | 257626640.0 Ops/sec |
Native + toFixed | 17886812.0 Ops/sec |
decimal.js | 466788.2 Ops/sec |
big.js | 379324.4 Ops/sec |
bignumber.js | 487826.2 Ops/sec |
Let's dive into the details of what's being tested on MeasureThat.net.
What is being tested?
The benchmark is testing the performance of different libraries for handling large decimal numbers:
bignumber.js
big.js
decimal.js
Each library has its own implementation of arithmetic operations (addition, multiplication, etc.) and formatting functions (e.g., toFixed()
).
Options being compared
The benchmark is comparing the performance of each library under two different scenarios:
toFixed()
function.Pros and Cons
Here's a brief summary of each library's pros and cons:
Other considerations
When choosing a library for handling large decimal numbers, consider the following factors:
Library descriptions
Here's a brief description of each library:
Special JS features or syntax
None of the libraries mentioned above uses special JavaScript features or syntax that would require additional explanation.