Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js (no to string)
(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 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.2/bignumber.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/big.js/6.1.1/big.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.3.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).toString();
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 (4)
Previous results
Fork
Test case name
Result
Native
decimal.js
big.js
bignumber.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
946721664.0 Ops/sec
decimal.js
608376.3 Ops/sec
big.js
958182.8 Ops/sec
bignumber.js
527927.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The provided benchmark compares the performance of three libraries: `bignumber.js`, `big.js`, and `decimal.js`. These libraries are designed to handle large decimal numbers with high precision. The benchmark focuses on the execution time of arithmetic operations, specifically addition, multiplication, and exponentiation. **Library Options Compared** 1. **Native**: This option uses built-in JavaScript functionality for arithmetic operations. No library is involved. 2. **bignumber.js**, **big.js**, and **decimal.js**: These libraries provide their own implementations of decimal numbers and arithmetic operations. **Pros and Cons of Each Approach:** * **Native**: Pros: + No dependencies or additional overhead. + No risk of bugs or security vulnerabilities introduced by external libraries. Cons: + May not be optimized for performance, especially for large numbers. + Limited precision (typically 64 bits). * **bignumber.js**, **big.js**, and **decimal.js**: Pros: + High precision (often hundreds or thousands of digits). + Optimized for performance, with various algorithms and data structures. Cons: + Additional dependencies and overhead. + May introduce bugs or security vulnerabilities if not used correctly. **Library Descriptions:** * **bignumber.js**: Developed by Mike McIlfatrick, this library provides high-precision arithmetic for JavaScript. It supports various number systems, including decimal, hexadecimal, and binary. * **big.js**: Created by Mike McIlfatrick (same author as bignumber.js), this library focuses on big integer arithmetic with support for multiple number systems. * **decimal.js**: Developed by Ryan Davis, this library provides precise decimal arithmetic with high precision and support for various operations. **Special JS Feature:** The benchmark uses a special JavaScript feature called `toString()` to convert the result of an operation into a string. This is done to measure the overhead of converting numbers from their native representation to strings. **Other Considerations:** * **Precision**: The choice of library affects the precision of arithmetic operations. Higher precision libraries like bignumber.js and big.js may be necessary for certain applications. * **Performance**: The performance difference between libraries can be significant, especially for large numbers or complex operations. * **Readability and Maintainability**: While performance is crucial, readability and maintainability should also be considered when choosing a library. **Alternative Libraries:** Other notable libraries that provide high-precision arithmetic in JavaScript include: * **Fraction.js**: A lightweight library for working with fractions and rational numbers. * **decimal.js** (other variants): There are various implementations of decimal arithmetic, such as `decimal.js` by Ryan Davis (used in the benchmark). Keep in mind that this is not an exhaustive list, and there may be other libraries available depending on specific requirements or use cases.
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 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?