Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js only calculation without toString()
(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:
Native vs Native + toFixed vs decimal.js vs big.js vs bignumber.js
Created:
3 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:
Native
var a = 0.1; var b = 0.2; ((a + b) * b);
Native + toFixed
var a = 0.1; var b = 0.2; ((a + b) * b);
decimal.js
var a = new Decimal("0.1"); var b = new Decimal("0.2"); a.plus(b).times(b);
big.js
var a = new Big("0.1"); var b = new Big("0.2"); a.plus(b).mul(b);
bignumber.js
var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).multipliedBy(b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Native
Native + toFixed
decimal.js
big.js
bignumber.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.1:latest
, generated one year ago):
Let's break down what's being tested in this benchmark. **Overview** The benchmark is comparing the performance of four different approaches to perform a simple mathematical calculation: `(a + b) * b`, where `a` and `b` are decimal numbers. **Libraries involved** Three libraries are being compared: 1. **Decimal.js**: A JavaScript library for decimal arithmetic. 2. **Big.js**: A JavaScript library for arbitrary-precision arithmetic. 3. **Bignumber.js**: Another JavaScript library for arbitrary-precision arithmetic, similar to Big.js. These libraries aim to provide more precise and flexible ways of handling decimal numbers compared to the built-in JavaScript Number type. **Test cases** Five test cases are being executed: 1. **Native**: The calculation is performed using only native JavaScript `Number` type. 2. **Native + toFixed**: Similar to Native, but with an added `.toFixed()` method call to ensure that the result is a string representation of the decimal number (to avoid potential precision issues). 3. **Decimal.js**: The calculation is performed using Decimal.js library's `Decimal` class. 4. **Big.js**: The calculation is performed using Big.js library's `Big` class. 5. **Bignumber.js**: The calculation is performed using Bignumber.js library's `BigNumber` class. **Pros and Cons** Here are some general pros and cons of each approach: 1. **Native**: * Pros: Fast, lightweight, and widely supported by all browsers. * Cons: May lose precision for certain decimal calculations (e.g., when multiplying two decimal numbers). 2. **Decimal.js**, **Big.js**, and **Bignumber.js**: * Pros: Can preserve precise decimal arithmetic, often with a higher performance than Native when dealing with large decimal numbers or complex calculations. * Cons: May have additional dependencies and slower performance in some scenarios due to the overhead of library usage. **Alternative approaches** If you're looking for alternative ways to perform decimal arithmetic in JavaScript: 1. **Use the built-in Number type with caution**: Be aware that using native `Number` type may lead to precision issues, especially when dealing with complex calculations or large decimal numbers. 2. **Other libraries**: Besides Decimal.js, Big.js, and Bignumber.js, there are other libraries available for decimal arithmetic in JavaScript, such as Fraction.js (mentioned in the Html Preparation Code). 3. **Consider using a more modern approach**: With the rise of modern JavaScript features like BigInt, you may want to explore alternative approaches that take advantage of these built-in types. I hope this explanation helps!
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
number / bignumber.js / big.js / decimal.js
number vs bignumber.js vs big.js vs decimal.js
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?