Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js vs. Fraction.js (v2, with script links corrected)
(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 Native + toFixed vs decimal.js vs big.js vs bignumber.js vs bigdecimal.js vs Fraction.js
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/bigdecimal@0.6.1/lib/bigdecimal.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bignumber.js@9.0.1/bignumber.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/big.js@6.0.3/big.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/decimal.js@10.2.1/decimal.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fraction.js@4.0.13/fraction.min.js"></script>
Tests:
Native
var a = 0.1; var b = 0.2; ((a + b) * b).toString();
Native + toFixed
var a = 0.1; var b = 0.2; ((a + b) * b).toFixed(9);
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();
bigdecimal.js
var a = new BigDecimal("0.1"); var b = new BigDecimal("0.2"); a.add(b).multiply(b).toString();
Fraction.js
var a = new Fraction("0.1"); var b = new Fraction("0.2"); a.add(b).mul(b).toString();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
Native
Native + toFixed
decimal.js
big.js
bignumber.js
bigdecimal.js
Fraction.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 break down the benchmark and explain what is being tested, the options being compared, their pros and cons, and other considerations. **Benchmark Definition** The benchmark is testing the performance of different libraries for working with decimal arithmetic in JavaScript: 1. `bignumber.js` 2. `big.js` 3. `decimal.js` 4. `Fraction.js` (v2) **Test Cases** Each test case has a unique definition, but they all aim to perform a simple calculation: `(a + b) * b`, where `a` and `b` are decimal numbers. **Options being compared** The four libraries offer different approaches to working with decimals: 1. **Native**: JavaScript's built-in `Number` type is used for floating-point arithmetic, which is prone to rounding errors. 2. **`decimal.js`**: A dedicated library for decimal arithmetic, providing precise control over rounding and calculations. 3. **`bignumber.js`**, **`big.js`**, and **`Fraction.js`** (v2): These libraries provide their own implementation of decimal arithmetic, with varying degrees of precision and features. **Pros and Cons** Here's a brief summary of each library's strengths and weaknesses: 1. **Native**: Fast, but prone to rounding errors. Suitable for simple cases where precision is not critical. 2. **`decimal.js`**: Precise control over rounding, suitable for most decimal arithmetic tasks. However, might be slower than native or optimized libraries. 3. **`bignumber.js`**: * Pros: Supports large numbers, precise calculations, and has a user-friendly API. * Cons: Might be slower than native or optimized libraries, and its large number support can lead to performance issues if not used carefully. 4. **`big.js`**: Similar to `bignumber.js`, but with fewer features and possibly better performance due to optimizations. 5. **`Fraction.js`** (v2): Designed for rational arithmetic, providing exact calculations and potentially better performance than decimal libraries. **Other Considerations** When choosing a library for decimal arithmetic: * Precision: If you need high precision, `decimal.js`, `bignumber.js`, or `Fraction.js` might be a better choice. * Performance: For simple cases where precision is not critical, native or optimized libraries like `big.js` might be faster. * Features: Consider the specific features you need, such as large number support, rational arithmetic, or user-friendly APIs. **Benchmark Results** The benchmark results show that each library performs differently on the same test case. The top-performing libraries are often those with optimized implementations or fewer dependencies (e.g., `big.js` and native). However, precision is crucial in many cases, so `decimal.js` and `bignumber.js` might still be preferred for their precise calculations. In summary, this benchmark compares the performance of four JavaScript libraries for decimal arithmetic, highlighting their strengths and weaknesses. When choosing a library, consider your specific needs regarding precision, performance, and features.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js vs. Fraction.js (without native)
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?