Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs native benchmark: compareTo
(version: 0)
- https://github.com/iriscouch/bigdecimal.js/tree/v0.6.1 - 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 - https://github.com/infusion/Fraction.js/tree/v4.0.12
Comparing performance of:
Native vs bignumber.js
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://rawgit.com/iriscouch/bigdecimal.js/v0.6.1/lib/bigdecimal.js"></script> <script src="https://rawgit.com/MikeMcl/bignumber.js/v9.0.0/bignumber.min.js"></script> <script src="https://rawgit.com/MikeMcl/big.js/v5.2.2/big.min.js"></script> <script src="https://rawgit.com/MikeMcl/decimal.js/v10.2.0/decimal.min.js"></script> <script src="https://rawgit.com/infusion/Fraction.js/v4.0.12/fraction.min.js"></script>
Script Preparation code:
var a = Number("0.1"); var b = Number("0.2"); var a1 = new BigNumber("0.1"); var b1 = new BigNumber("0.2");
Tests:
Native
a - b;
bignumber.js
a1.comparedTo(b1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
bignumber.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
106539024.0 Ops/sec
bignumber.js
23237788.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and options. **Benchmark Definition** The benchmark compares the performance of two libraries: Big Number (from Mike McLean) and native JavaScript for large number comparisons. The test uses four different libraries: 1. `bignumber.js` by Mike McLean 2. `BigDecimal.js` by Iris Couch 3. `big.js` by Mike McLean 4. `decimal.js` by Mike McLean 5. `Fraction.js` by Infusion **Options Compared** The benchmark compares the execution time of two operations: 1. Subtracting two numbers (`a - b`) 2. Comparing two large numbers using the `comparedTo()` method (only for `bignumber.js`) **Pros and Cons of Different Approaches** 1. **Native JavaScript**: Native JavaScript uses built-in data types like `Number` or `BigInt` to represent large numbers. This approach is lightweight and fast, as it leverages the compiler's optimizations. However, it may not provide accurate results for very large numbers due to numerical precision issues. 2. **Big Number (bignumber.js)**: Big Number uses a custom implementation of arbitrary-precision arithmetic. This approach provides high accuracy and support for complex number operations but is typically slower than native JavaScript due to its overhead. 3. **BigDecimal.js**: BigDecimal uses the IEEE 754 floating-point standard, which provides high accuracy but may be slower than Big Number due to its additional computations. **Library Descriptions** 1. `bignumber.js` by Mike McLean: A custom implementation of arbitrary-precision arithmetic for large numbers. It provides high accuracy and support for complex number operations. 2. `BigDecimal.js` by Iris Couch: Builds upon the IEEE 754 floating-point standard, providing high accuracy but potentially slower performance. 3. `big.js` by Mike McLean: Similar to Big Number (bignumber.js) but with some differences in implementation details. 4. `decimal.js` by Mike McLean: Designed for decimal arithmetic, providing more accurate results than native JavaScript's floating-point numbers. **Special JS Features** The benchmark uses the following special JavaScript features: 1. **BigInt**: Used to represent large integers (not used in this benchmark). 2. **Custom implementation of arbitrary-precision arithmetic**: Used by Big Number (bignumber.js) and big.js. **Other Alternatives** Some other alternatives for large number comparisons include: 1. `BigInt`: The built-in support for large integers in modern JavaScript engines. 2. `decimal.js` by Mike McLean: A library specifically designed for decimal arithmetic, which may be more accurate than native JavaScript's floating-point numbers. 3. `Decimal.js` by GitHub user 'pkozlowski23': Another alternative implementation of arbitrary-precision decimal arithmetic. In conclusion, the benchmark provides a comprehensive comparison of different libraries and approaches for large number comparisons in JavaScript. It highlights the trade-offs between accuracy, performance, and library complexity.
Related benchmarks:
bignumber library vs native benchmark: compareTo
bignumber.js vs native benchmark: string to number
number / bignumber.js / big.js / decimal.js
number vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?