Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber library 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>
Tests:
Native
var a = Number("0.1"); var b = Number("0.2"); a - b;
bignumber.js
var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.comparedTo(b);
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
167316464.0 Ops/sec
bignumber.js
2319807.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **Benchmark Definition** The benchmark compares the performance of different JavaScript libraries that implement decimal arithmetic: `bignumber`, `big.js`, `decimal.js`, and `Fraction.js`. These libraries aim to provide more accurate and efficient decimal arithmetic compared to native JavaScript's floating-point numbers. The choice of library affects how calculations are performed, especially when dealing with high-precision arithmetic. **Options Compared** The benchmark compares the following options: 1. **Native JavaScript**: Uses native JavaScript's floating-point numbers for decimal arithmetic. 2. **bignumber.js**, **big.js**, and **decimal.js**: Implement decimal arithmetic using their respective libraries. These libraries provide different implementations of decimal arithmetic, which can affect performance, accuracy, and complexity. **Pros and Cons** Here are some pros and cons of each option: 1. **Native JavaScript**: * Pros: Simple, widely supported, and often included in browsers. * Cons: May lose precision or produce unexpected results for high-precision arithmetic. 2. **bignumber.js**, **big.js**, and **decimal.js**: * Pros: Provide more accurate and efficient decimal arithmetic, with better support for high-precision calculations. * Cons: + More complex implementation, which can lead to slower performance. + May require additional setup or configuration. **Library Descriptions** 1. **bignumber.js**: Developed by Mike Mcl, it aims to provide a simple and efficient way to perform decimal arithmetic. It's designed for high-precision calculations and supports features like rounding, scaling, and formatting. 2. **big.js**: Also developed by Mike Mcl, big.js provides a more extensive set of features than bignumber.js, including support for arbitrary-precision integers and advanced mathematical functions. 3. **decimal.js**: Developed by Mike Mcl as well, decimal.js is designed for high-precision calculations and supports a wide range of decimal arithmetic operations. 4. **Fraction.js**: Developed by infusion, Fraction.js provides a simple and lightweight way to work with rational numbers (fractions). It's suitable for applications where exact fractions are necessary. **Special JavaScript Features or Syntax** The benchmark uses the `Number` function to create floating-point numbers from strings, which is a common pattern in JavaScript. However, it doesn't use any special JavaScript features or syntax that require deep knowledge of the language. **Alternatives** If you're looking for alternatives to these libraries, consider: 1. **IEEE 754 Floating-Point Arithmetic**: A widely used standard for floating-point arithmetic, implemented by many browsers and programming languages. 2. **JavaScript modules like `js-bigint` or `decimal.js`**: These modules provide additional decimal arithmetic capabilities beyond what's offered by the listed libraries. 3. **Other libraries like `mathjs` or `numjs`**: These libraries offer more comprehensive mathematical capabilities, including decimal arithmetic. Keep in mind that the choice of library ultimately depends on your specific use case and requirements.
Related benchmarks:
bignumber library benchmark
bignumber.js vs native benchmark: compareTo
bignumber.js vs native benchmark: string to number
number vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?