Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
number / bignumber.js / big.js / decimal.js
(version: 0)
- https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Number - 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:
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
const a = parseFloat('123.456'); const b = parseFloat('123.456'); //const c = isNan(a) && isNan(b); const d = a > b || a < b; const e = (a + b) * b;
decimal.js
const a = new Decimal('123.456'); const b = new Decimal('123.456'); //const c = a.isNan() && b.isNan(); const d = a.greaterThan(b) || a.lessThan(b); const e = a.plus(b).times(b);
big.js
const a = new Big('123.456'); const b = new Big('123.456'); //const c = a.isNan() && b.isNan(); const d = a.gt(b) || a.lt(b); const e = a.plus(b).mul(b);
bignumber.js
var a = new BigNumber('123.456'); var b = new BigNumber('123.456'); //const c = a.isNan() && b.isNan(); const d = a.gt(b) || a.lt(b); const e = 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:
19 hours ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native
22859624.0 Ops/sec
decimal.js
1122733.5 Ops/sec
big.js
2037565.8 Ops/sec
bignumber.js
1208179.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of numerical calculations in JavaScript is an interesting task. **What's being tested?** The provided benchmark tests four different approaches to perform numerical calculations: 1. **Native**: The native JavaScript implementation, which uses floating-point numbers (64-bit IEEE 754). 2. **Big.js**: A library that provides support for arbitrary-precision arithmetic, using a custom binary format. 3. **Decimal.js**: Another library that provides support for decimal arithmetic, with a focus on precision and accuracy. 4. **Bignumber.js**: A library that provides support for arbitrary-precision arithmetic, similar to Big.js. **Options compared** Each test case compares the performance of different numerical libraries or approaches: * `decimal.js` vs `big.js`: Both libraries provide support for decimal arithmetic, but with slightly different implementations and optimizations. * `bignumber.js` vs `big.js`: Both libraries provide support for arbitrary-precision arithmetic, but with different binary formats and optimization strategies. * Native JavaScript vs other libraries: The native implementation is compared to the performance of three third-party libraries. **Pros and cons** Here's a brief summary of the pros and cons of each approach: 1. **Native JavaScript**: * Pros: Fast and lightweight, as it's implemented in C++ and optimized for performance. * Cons: Limited precision (64-bit IEEE 754) and may exhibit numerical instability issues. 2. **Big.js**: * Pros: Provides a fast and efficient implementation of arbitrary-precision arithmetic, with good support for decimal arithmetic. * Cons: May have some overhead due to its custom binary format and optimization strategy. 3. **Decimal.js**: * Pros: Focuses on precision and accuracy, making it suitable for applications where high precision is required. * Cons: May be slower than Big.js or native JavaScript due to its additional checks and verification mechanisms. 4. **Bignumber.js**: * Pros: Similar to Big.js, providing a fast and efficient implementation of arbitrary-precision arithmetic. * Cons: May have some differences in binary format and optimization strategy compared to Big.js. **Other considerations** When choosing a numerical library or approach, consider the following factors: * Precision requirements: If you need high precision, Decimal.js might be a better choice. For general-purpose numerical calculations, native JavaScript or Big.js/Bignumber.js might be sufficient. * Performance: Native JavaScript is generally the fastest, followed by Bignumber.js and Big.js. * Developer experience: All three libraries are designed to be easy to use and provide good documentation. **Alternatives** If you're looking for alternative libraries or approaches, consider: 1. **Fraction.js**: A library that provides support for rational arithmetic and decimal arithmetic, with a focus on simplicity and performance. 2. **Arbitrary-precision arithmetic in Node.js**: Some Node.js implementations, like `arbitrary-precision`, provide built-in support for arbitrary-precision arithmetic. Note: The choice of numerical library or approach ultimately depends on your specific use case, performance requirements, and developer preferences.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js vs. math.min.js
number ass testing v2
number vs bignumber.js vs big.js vs decimal.js
bignumber.js vs. big.js vs. decimal.js in 2024-05-03
Comments
Confirm delete:
Do you really want to delete benchmark?