Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
(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:
2 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:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
decimal.js
693826.1 Ops/sec
big.js
1271232.1 Ops/sec
bignumber.js
676916.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared options, pros and cons of those approaches, and other considerations. **Benchmark Overview** The benchmark compares the performance of three libraries: `bignumber.js`, `big.js`, and `decimal.js`. The test cases are designed to measure the execution time of specific arithmetic operations using each library. **Test Cases** There are three individual test cases: 1. **`decimal.js`**: Measures the performance of decimal arithmetic using the `Decimal` class. * Benchmark Definition: `var a = new Decimal("0.1"); var b = new Decimal("0.2"); a.plus(b).times(b).toString();` 2. **`big.js`**: Measures the performance of big integer arithmetic using the `Big` class. * Benchmark Definition: `var a = new Big("0.1"); var b = new Big("0.2"); a.plus(b).mul(b).toString();` 3. **`bignumber.js`**: Measures the performance of big number arithmetic using the `BigNumber` class. * Benchmark Definition: `var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).multipliedBy(b).toString();` **Comparison of Options** The three libraries are compared in terms of their performance, precision, and usability. * **Precision**: All three libraries support arbitrary-precision arithmetic, which means they can handle very large numbers without losing accuracy. * **Performance**: The benchmark measures the execution time of each operation. `bignumber.js` is expected to be faster than the other two due to its optimized JavaScript implementation. * **Usability**: Each library has its own strengths and weaknesses: + `decimal.js`: Designed for precise decimal arithmetic, but may not be suitable for very large numbers. + `big.js`: Provides a simple and intuitive API, but may not offer the same level of performance as `bignumber.js`. + `bignumber.js`: Offers high performance and a robust feature set, making it a popular choice for big number arithmetic. **Pros and Cons** * **`decimal.js`**: + Pros: Precise decimal arithmetic, easy to use. + Cons: May not be suitable for very large numbers, slower than `bignumber.js`. * **`big.js`**: + Pros: Simple and intuitive API, fast execution times. + Cons: May not offer the same level of performance as `bignumber.js`, limited features compared to other libraries. * **`bignumber.js`**: + Pros: High performance, robust feature set, suitable for very large numbers. + Cons: Steeper learning curve due to its JavaScript implementation. **Other Considerations** * **Fraction.js**: Although not explicitly mentioned in the benchmark definition, Fraction.js is a separate library that provides similar functionality to `decimal.js`. Its inclusion would further complicate the comparison. * **NativetoFixed()**: The native JavaScript method `toFixed()` is also included in the benchmark. This method uses the browser's native arithmetic implementation and may not offer the same level of performance or precision as the libraries. **Alternatives** If you're looking for alternatives to these libraries, consider: * **`Big.js`**: A JavaScript implementation of the Big Number library. * **`decimal.js`**: Another popular decimal arithmetic library. * **`js-bigint`**: A lightweight JavaScript implementation of arbitrary-precision integers. * **Native `toFixed()`**: For simple cases where precision and performance are not critical. Ultimately, the choice of library depends on your specific requirements, such as precision, performance, or ease of use.
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()
number / bignumber.js / big.js / decimal.js
number vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?