Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js (I) no native
(version: 0)
- https://github.com/MikeMcl/bignumber.js/tree/v9.0.0 - https://github.com/MikeMcl/big.js/tree/v5.2.2 - https://github.com/MikeMcl/decimal.js/tree/v10.2.0
Comparing performance of:
decimal.js vs big.js vs bignumber.js
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--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.1/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-->
Tests:
decimal.js
var a = new Decimal("0.1"); var b = new Decimal("0.2"); a.plus(b).times(b).toString();
big.js
var a = new Big("0.1"); var b = new Big("0.2"); a.plus(b).mul(b).toString();
bignumber.js
var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).multipliedBy(b).toString();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
decimal.js
big.js
bignumber.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
13 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
decimal.js
1587904.5 Ops/sec
big.js
3961824.2 Ops/sec
bignumber.js
1583353.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared, and their pros/cons. **Benchmark Overview** The benchmark is comparing three libraries: `big.js`, `decimal.js`, and `bignumber.js`. These libraries are designed to handle large numbers and decimal calculations in JavaScript. The test focuses on measuring the performance of each library when performing a specific calculation: `(a + b) * b` (where `a` and `b` are two decimal values). **Library Overview** * **big.js**: A high-performance, open-source library for large number arithmetic. * **decimal.js**: A JavaScript implementation of the Decimal class, which provides support for decimal arithmetic with precise control over rounding and scaling. * **bignumber.js**: A popular library for arbitrary-precision arithmetic in JavaScript. **Test Cases** Each test case is a small script that uses one of these libraries to perform the same calculation. The differences lie in how the calculation is expressed: 1. `decimal.js`: ```javascript var a = new Decimal("0.1"); var b = new Decimal("0.2"); a.plus(b).times(b).toString(); ``` This test case creates two decimal numbers using `Decimal()` and performs arithmetic operations on them. 2. `big.js`: ```javascript var a = new Big("0.1"); var b = new Big("0.2"); a.plus(b).mul(b).toString(); ``` This test case uses the `Big()` constructor to create two large numbers and performs arithmetic operations using the `plus()` and `mul()` methods. 3. `bignumber.js`: ```javascript var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).multipliedBy(b).toString(); ``` This test case uses the `BigNumber()` constructor to create two large numbers and performs arithmetic operations using the `plus()` and `multipliedBy()` methods. **Pros/Cons of each approach** * **big.js**: High performance, but might be more complex for beginners due to its unique API. + Pros: Fast execution times, good memory usage management. + Cons: Steeper learning curve, limited support for non-numeric input validation. * **decimal.js**: Precise control over rounding and scaling, easy to use. + Pros: Robust error handling, flexible configuration options. + Cons: Lower performance compared to `big.js`, might require more memory usage due to extra data structures. * **bignumber.js**: Wide support for various input formats (e.g., strings, numbers), robust API. + Pros: Easy to use, supports a wide range of inputs, has extensive documentation. + Cons: Lower performance compared to `big.js`, relies on caching mechanism which can lead to performance issues if not properly configured. **Device-specific considerations** The benchmark is run in a Chrome 96 browser on Windows Desktop devices. The results may vary across different operating systems, browsers, and hardware configurations. **Alternatives** Other libraries that might be used for large number arithmetic include: * **Fraction.js**: A library for rational number arithmetic. * **MathJS**: A JavaScript library for mathematical operations with support for large numbers. * **LibNum**: A C++ library that can be used in JavaScript via an adapter, providing high-performance arbitrary-precision arithmetic. Please note that the suitability of each library depends on the specific requirements and constraints of your project.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
bignumber.js vs. big.js vs. decimal.js only calculation without toString()
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
bignumber.js vs. big.js vs. decimal.js@10.4.3 (I)
Comments
Confirm delete:
Do you really want to delete benchmark?