Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js (I) 12
(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 decimal.js vs big.js vs bignumber.js
Created:
4 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 = 0.1; var b = 0.2; Math.fround((a + b) * b).toString();
decimal.js
var a = new Decimal("0.1"); var b = new Decimal("0.2"); a.plus(b).times(b).toString();
big.js
var a = new Big("0.1"); var b = new Big("0.2"); a.plus(b).mul(b).toString();
bignumber.js
var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).multipliedBy(b).toString();
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:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The benchmark compares the performance of three libraries for decimal arithmetic: big.js, bignumber.js, and decimal.js. The test cases focus on the `fround()` function, which converts a number to a fixed-point representation, and the `plus()`, `times()`, and `toString()` methods for performing basic arithmetic operations. **Libraries and Their Purpose** 1. **big.js**: big.js is a JavaScript library for precise decimal arithmetic. It provides a way to work with large numbers without losing precision due to rounding errors. 2. **bignumber.js**: bignumber.js is another popular library for decimal arithmetic in JavaScript. It's designed to be fast and efficient while maintaining high precision. 3. **decimal.js**: decimal.js is a lightweight library that provides a simple way to work with decimal numbers in JavaScript. It's optimized for performance and ease of use. **Test Cases** The benchmark consists of four test cases, each using one of the libraries: 1. **Native**: This test case uses the built-in `Math.fround()` function, which converts a number to a fixed-point representation. 2. **decimal.js**: This test case uses the `Decimal` class from decimal.js to perform arithmetic operations. 3. **big.js**: This test case uses the `Big` class from big.js to perform arithmetic operations. 4. **bignumber.js**: This test case uses the `BigNumber` class from bignumber.js to perform arithmetic operations. **Comparison of Approaches** Each library has its pros and cons: * **Native**: The built-in `Math.fround()` function is simple and efficient, but it may lose precision due to rounding errors. It's a good choice when precision is not critical. * **decimal.js**: decimal.js is lightweight and easy to use, making it a good choice for small projects or prototyping. However, it might be slower than other libraries like big.js and bignumber.js. * **big.js** and **bignumber.js**: Both libraries are designed for high-performance decimal arithmetic and offer more features than decimal.js. They're suitable for larger projects that require precise calculations. **Considerations** When choosing a library, consider the following factors: * Precision requirements: If you need high precision, choose big.js or bignumber.js. If you can tolerate some rounding errors, native or decimal.js might be sufficient. * Performance: If speed is critical, choose big.js or bignumber.js. They're optimized for performance and are likely to be faster than decimal.js. * Ease of use: If simplicity and ease of use are important, consider decimal.js. **Other Alternatives** Besides the three libraries mentioned above, there are other options available: * **Fraction.js**: A library for working with rational numbers in JavaScript. It's designed for high-performance arithmetic operations and is suitable for projects that require precise calculations. * **BigDecimal.js**: A JavaScript implementation of the BigInteger class from Java. It provides a way to work with large integers and decimal numbers. In summary, the choice of library depends on your specific requirements, performance needs, and ease of use preferences. By understanding the strengths and weaknesses of each library, you can make an informed decision for your project.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
bignumber.js vs. big.js vs. decimal.js (I) no native
bignumber.js vs. big.js vs. decimal.js only calculation without toString()
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
bignumber.js vs. big.js vs. decimal.js@10.4.3 (I)
Comments
Confirm delete:
Do you really want to delete benchmark?