Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bigint vs. bignumber.js vs. big.js vs. decimal.js with exponentiation
(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; var c = 31; (((a + b) * b) ^ c).toString();
BigInt
var a = 100n; var b = 200000n; var c = 31n; (((a + b) * b) ^ c).toString();
decimal.js
var a = new Decimal("100"); var b = new Decimal("200000"); var c = new Decimal("31"); a.plus(b).times(b).pow(c).toString();
big.js
var a = new Big("100"); var b = new Big("200000"); var c = new Big("31"); a.plus(b).mul(b).pow(c).toString();
bignumber.js
var a = new BigNumber("100"); var b = new BigNumber("200000"); var c = new BigNumber("31"); a.plus(b).multipliedBy(b).pow(c).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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 YaBrowser/24.6.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
80848400.0 Ops/sec
BigInt
24201766.0 Ops/sec
decimal.js
224351.7 Ops/sec
big.js
0.0 Ops/sec
bignumber.js
247559.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **What is tested:** The benchmark tests the performance of different libraries for handling large numbers in JavaScript: 1. Native (JavaScript built-in support) 2. BigInt (a new type introduced in ECMAScript 2020 for arbitrary-precision integers) 3. decimal.js, big.js, and bignumber.js (three popular libraries for working with large numbers) **Options compared:** The benchmark compares the performance of each library when performing a specific mathematical operation: * `(((a + b) * b) ^ c).toString()` This expression calculates the result of exponentiating the product of two large numbers (`b`) and an intermediate value (`c`), converted to a string. **Pros and Cons:** 1. **Native**: The built-in JavaScript support is likely to be fast, as it's optimized for performance. * Pros: Fast, no dependencies required. * Cons: Limited support for arbitrary-precision integers, potential performance issues with very large numbers. 2. **BigInt**: This new type provides efficient and accurate support for arbitrary-precision integers. * Pros: Efficient, accurate, and modern support for large numbers. * Cons: Requires ECMAScript 2020 or later support, may have compatibility issues in older browsers. 3. **decimal.js**, **big.js**, and **bignumber.js**: These libraries provide alternative implementations of the arithmetic operations for large numbers. * Pros: May offer better performance or features than Native or BigInt. * Cons: Introduce additional dependencies, potential performance overhead. **Libraries explained:** 1. **decimal.js**: A library that provides decimal arithmetic, including support for arbitrary-precision integers. 2. **big.js**: A library that provides big number arithmetic, including support for arbitrary-precision integers. 3. **bignumber.js**: A library that provides bignumber arithmetic, including support for arbitrary-precision integers. **Special JS feature or syntax:** The benchmark uses the `n` suffix to denote BigInt numbers (e.g., `100n`, `200000n`). This is a relatively recent addition to JavaScript, introduced in ECMAScript 2019. **Alternatives:** If you need alternative libraries for handling large numbers in JavaScript, consider: 1. **Fraction.js**: A library that provides fractional arithmetic. 2. **Mathjs**: A math engine that supports arbitrary-precision numbers and advanced mathematical operations. Keep in mind that each library has its strengths and weaknesses, and the choice of which one to use depends on your specific requirements and constraints.
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()
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?