Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bigint 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:
Native vs BigInt vs 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:
Native
var a = 100; var b = 200000; ((a + b) * b).toString();
BigInt
var a = 100n; var b = 200000n; ((a + b) * b).toString();
decimal.js
var a = new Decimal("100"); var b = new Decimal("200000"); a.plus(b).times(b).toString();
big.js
var a = new Big("100"); var b = new Big("200000"); a.plus(b).mul(b).toString();
bignumber.js
var a = new BigNumber("100"); var b = new BigNumber("200000"); a.plus(b).multipliedBy(b).toString();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Native
BigInt
decimal.js
big.js
bignumber.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
129670192.0 Ops/sec
BigInt
47553508.0 Ops/sec
decimal.js
2176862.2 Ops/sec
big.js
3501075.2 Ops/sec
bignumber.js
2365919.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks. **What is being tested?** The provided JSON represents a benchmarking test case, where different libraries are compared to measure their performance in performing arithmetic operations on large numbers. Specifically: * `bigint`: The native JavaScript `BigInt` type, which was introduced in ECMAScript 2020. * `bignumber.js`, `big.js`, and `decimal.js`: External libraries that provide support for arbitrary-precision arithmetic. **Options being compared** The test cases compare the performance of each library or the native `BigInt` type in performing a simple arithmetic operation: 1. `(a + b) * b`.toString()` This operation is used to test the performance of each library in handling large numbers and performing multiplication, addition, and conversion to string. **Pros and Cons of different approaches:** * **Native `BigInt`**: The native JavaScript `BigInt` type provides a simple and efficient way to perform arbitrary-precision arithmetic. It's a good choice when you don't need to support older browsers or environments that don't support `BigInt`. + Pros: Fast, efficient, and widely supported. + Cons: May not be as flexible or customizable as other libraries. * **`bignumber.js`, `big.js`, and `decimal.js`**: These libraries provide a more comprehensive set of features for arbitrary-precision arithmetic. They may offer additional functionality, such as support for decimal arithmetic or advanced mathematical operations. + Pros: More feature-rich, flexible, and customizable than native `BigInt`. + Cons: May be slower due to the overhead of an external library, and may not be supported in older browsers or environments. **Library descriptions and purposes:** * **`bignumber.js`**: A popular JavaScript library for arbitrary-precision arithmetic. It provides a simple and intuitive API for performing mathematical operations on large numbers. * **`big.js`**: Another popular JavaScript library for arbitrary-precision arithmetic, which offers a more extensive set of features than `bignumber.js`. * **`decimal.js`**: A JavaScript library specifically designed for decimal arithmetic, offering support for precise control over rounding and precision. **Special JS feature or syntax:** The test case uses the `n` suffix to denote large integers, which is a relatively new feature in ECMAScript (ECMAScript 2020). This allows developers to create large integer values with ease, without having to resort to strings or other workarounds. The use of `BigInt` and other libraries tests the performance and compatibility of these features across different browsers and environments. **Other alternatives:** * **`Fraction.js`**: A JavaScript library for rational arithmetic, which may be a more suitable choice for applications requiring precise control over fractional values. * **`Arbitrary-precision arithmetic libraries`:** There are many other libraries available that provide support for arbitrary-precision arithmetic, such as `Mathjs`, `Plural`, and `Sindicus`. These libraries may offer additional features or performance optimizations compared to the ones listed above.
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@10.4.3 (I)
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?