<!--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-->
new Decimal(1804)
.mul(new Decimal(10).pow(6 - 18))
.log(1.0001)
.round()
.neg()
.toNumber();
Math.log(1804 * 10 ** (6 - 18)) / Math.log(1.0001)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
decimal.js | |
Native |
Test name | Executions per second |
---|---|
decimal.js | 16897.1 Ops/sec |
Native | 4358659.0 Ops/sec |
Let's dive into the explanation of what is being tested in this benchmark.
Benchmark Definition
The benchmark compares three different libraries: bignumber.js
, big.js
, and decimal.js
. These libraries are designed to handle large numbers and mathematical operations that would be slow or unreliable with standard JavaScript arithmetic.
Options Compared
The benchmark tests the performance of each library for a specific mathematical operation:
decimal.js
: This library performs the calculation using decimal arithmetic, which is more precise than standard JavaScript floating-point arithmetic.Math
functions in JavaScript, such as Math.log
, to perform the calculation.bignumber.js
, big.js
: These libraries also perform decimal arithmetic, but with different optimizations and features.Pros and Cons
decimal.js
:bignumber.js
, big.js
:decimal.js
, and some features may not be as well-maintained.Library Descriptions
decimal.js
: A library that provides decimal arithmetic for JavaScript. It is designed to be easy to use and provides a simple API for performing calculations.bignumber.js
: A library that provides arbitrary-precision arithmetic for JavaScript. It is designed to be fast and feature-rich, but may have a steeper learning curve.big.js
: A library that provides arbitrary-precision arithmetic for JavaScript. It is designed to be fast and easy to use, with a focus on simplicity.Special JS Features or Syntax
None mentioned in this benchmark.
Other Alternatives
If you need high-performance arithmetic libraries, you may also consider:
Fraction.js
: A library that provides rational arithmetic (fractions) for JavaScript.Arbitrary-precision libraries like libgmpjs
: These libraries provide arbitrary-precision arithmetic and are often used in scientific computing applications.Keep in mind that the choice of library depends on your specific use case, performance requirements, and ease of use preferences.