Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bigint vs. bignumber.js vs. big.js vs. decimal.js with exponentiation3
(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
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.2.1/decimal.min.js"></script>
Tests:
Native
var a = 100; var b = 200000; var c = 31; (((a + b) * b) ).toString();
BigInt
var a = 100n; var b = 200000n; var c = 31n; (((a + b) * b) ).toString();
decimal.js
var a = new Decimal("100"); var b = new Decimal("200000"); var c = new Decimal("31"); a.plus(b).times(b).toString();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native
BigInt
decimal.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
101531072.0 Ops/sec
BigInt
43540848.0 Ops/sec
decimal.js
1227632.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark measures the performance of three libraries: bignumber.js, big.js, and decimal.js, in addition to native JavaScript's built-in support for large integers (BigInt) and exponentiation. **What is being tested?** In this benchmark, three different operations are compared: 1. **Native**: The native JavaScript implementation with built-in support for large integers (BigInt). 2. **BigInt**: Native JavaScript's BigInt library. 3. **decimal.js**: A library for decimal arithmetic. 4. **bignumber.js**, **big.js**: Two other libraries for working with large numbers. The benchmark tests the performance of these libraries when performing a simple operation: `((a + b) * b).toString();` where `a`, `b`, and `c` are large integers or decimal values. **Options compared** The options being compared are: * **Native**: Native JavaScript's built-in support for large integers (BigInt). * **BigInt**: Native JavaScript's BigInt library. * **decimal.js**: A library for decimal arithmetic. * **bignumber.js**, **big.js**: Two other libraries for working with large numbers. **Pros and Cons** Here are some pros and cons of each approach: * **Native**: + Pros: Built-in support, likely to be optimized for performance. + Cons: May not provide precise decimal arithmetic, may have limited support for certain operations. * **BigInt**: + Pros: Provides a safe and efficient way to work with large integers in JavaScript. + Cons: May introduce additional overhead compared to native implementation. * **decimal.js**: + Pros: Provides precise decimal arithmetic, supports a wide range of operations. + Cons: May introduce additional overhead due to the library's complexity. * **bignumber.js**, **big.js**: + Pros: Provide high-performance support for large numbers, often comparable to native implementation. + Cons: May require manual setup and management of library options. **Library descriptions** 1. **decimal.js**: A JavaScript library for decimal arithmetic that provides precise control over the precision and rounding behavior of decimal operations. 2. **bignumber.js**: A JavaScript library for working with large numbers that provides high-performance support for arithmetic operations, exponentiation, and more. 3. **big.js**: Another JavaScript library for working with large numbers that provides similar functionality to bignumber.js. **Special JS features or syntax** In the benchmark definition, special JS feature or syntax is used in the following ways: * `100n` and `200000n`: The `n` suffix indicates a BigInt literal. * `new Decimal("100")`: Creates a new instance of the decimal.js library with the value "100". **Alternatives** If you need to perform large integer arithmetic or precision decimal calculations in JavaScript, other alternatives include: * **Google's V8**: The JavaScript engine used by Google Chrome and other browsers, which provides built-in support for BigInt literals. * **ES6 Arithmetic Operations**: Native JavaScript's built-in arithmetic operations can also be used with BigInt literals, although this may introduce additional overhead.
Related benchmarks:
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
bigint vs. bignumber.js vs. big.js vs. decimal.js with exponentiation
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?