Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js vs. math.min.js
(version: 1)
- 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 -https://pagecdn.io/lib/mathjs/9.4.4/math.min.js
Comparing performance of:
Native vs Native + toFixed vs decimal.js vs big.js vs bignumber.js vs math.min.js
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<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://pagecdn.io/lib/mathjs/9.4.4/math.min.js"></script>
Tests:
Native
var a = 0.1; var b = 0.2; ((a + b) * b).toString();
Native + toFixed
var a = 0.1; var b = 0.2; ((a + b) * b).toFixed(9);
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();
math.min.js
var a = 0.1; var b = 0.2; math.chain(a) .add(b) .multiply(b) .done()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Native
Native + toFixed
decimal.js
big.js
bignumber.js
math.min.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of big number arithmetic in JavaScript. **What is tested?** The benchmark compares the performance of four libraries: 1. `big.js`: A library for working with large integers and decimals. 2. `decimal.js`: A library specifically designed for decimal arithmetic. 3. `bignumber.js`: A library for working with large numbers, similar to `big.js`, but with some additional features. 4. `math.min.js`: A lightweight library from the MathJS project that provides a way to perform arbitrary-precision arithmetic. The benchmark tests various approaches to performing big number arithmetic operations, including addition, multiplication, and concatenation. **Options compared** Here are the different options being compared: 1. **Native**: Using built-in JavaScript methods for floating-point numbers (e.g., `toString()`, `toFixed(9)`). 2. **Big.js + decimal.js**: Using the `big.js` library with decimal arithmetic. 3. **Bignumber.js**: Using the `bignumber.js` library for big number arithmetic. 4. **Math.min.js**: Using the `math.min.js` library from MathJS for arbitrary-precision arithmetic. **Pros and cons of each approach** 1. **Native**: Fast, but may lose precision due to floating-point limitations. * Pros: Easy to implement, fast execution. * Cons: May not provide accurate results due to floating-point issues. 2. **Big.js + decimal.js**: Provides a balance between performance and accuracy. * Pros: Accurate results, easy to use. * Cons: May be slower than native methods or `bignumber.js`. 3. **Bignumber.js**: Offers advanced features like rounding and scaling. * Pros: Flexible, accurate results. * Cons: May be slower than native methods or `big.js + decimal.js`. 4. **Math.min.js**: Provides a lightweight solution for arbitrary-precision arithmetic. * Pros: Extremely lightweight, fast execution. * Cons: May require additional setup and may not provide all the features of other libraries. **Library explanations** 1. **Big.js**: A library that provides support for large integers and decimals. It's designed to be highly performant and accurate. 2. **Decimal.js**: A library specifically designed for decimal arithmetic. It provides a range of methods for performing decimal operations, including rounding and scaling. 3. **Bignumber.js**: A library that extends `big.js` with additional features like rounding and scaling. It's designed to provide a balance between performance and accuracy. **Other alternatives** 1. **MathJS**: The MathJS project offers a range of libraries for mathematical computations, including arbitrary-precision arithmetic. 2. **IEEE 754**: The IEEE 754 standard provides a way to represent floating-point numbers in a more precise manner, which can be used to improve the accuracy of native methods. In summary, the benchmark compares four different approaches to big number arithmetic in JavaScript: using built-in methods (native), using libraries like `big.js` and `decimal.js`, or using `bignumber.js`. The choice of library depends on the trade-off between performance, accuracy, and feature set.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
bignumber.js vs. big.js vs. decimal.js (I) no native
bignumber.js vs. big.js vs. decimal.js (without native)
bignumber.js vs. big.js vs. decimal.js@10.4.3 (I)
Comments
Confirm delete:
Do you really want to delete benchmark?