Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
number vs bignumber.js vs big.js vs decimal.js
(version: 0)
- https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Number - 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:
2 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
const a = parseFloat('123.456'); const b = parseFloat('123.456'); const d = a > b || a < b;
decimal.js
const a = new Decimal('123.456'); const b = new Decimal('123.456'); const d = a.greaterThan(b) || a.lessThan(b);
big.js
const a = new Big('123.456'); const b = new Big('123.456'); const d = a.gt(b) || a.lt(b);
bignumber.js
var a = new BigNumber('123.456'); var b = new BigNumber('123.456'); const d = a.gt(b) || a.lt(b);
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. **What is being tested?** The benchmark measures the performance of different libraries for working with numbers in JavaScript: 1. `Number` (native JavaScript type) 2. `Big.js` 3. `Bignumber.js` 4. `Decimal.js` Specifically, the tests compare the performance of these libraries when performing arithmetic operations on floating-point numbers. **Options compared:** The benchmark compares four options: * Native `Number` type * `Big.js` * `Bignumber.js` * `Decimal.js` Each library has its own strengths and weaknesses, which we'll discuss next. **Pros and Cons of each approach:** 1. **Native `Number` type:** * Pros: Fastest performance, widely supported. * Cons: May exhibit behavior that's not predictable due to floating-point precision issues. 2. **Big.js:** * Pros: High-performance, accurate calculations, and good support for various operations (e.g., addition, subtraction, multiplication, division). * Cons: May require more memory usage compared to native `Number` type. 3. **Bignumber.js:** * Pros: Fast performance, high precision, and good support for various operations. * Cons: May be less suitable for very large numbers due to performance overhead. 4. **Decimal.js:** * Pros: High-performance, accurate calculations, and good support for various operations (e.g., addition, subtraction, multiplication, division). * Cons: May require more memory usage compared to native `Number` type. **Libraries used in the tests:** 1. `Big.js`: A library for fast and precise arithmetic with large numbers. 2. `Bignumber.js`: A library for performing mathematical operations on very large and very small numbers. 3. `Decimal.js`: A library for performing accurate calculations with decimal numbers. **Special JS features or syntax:** None mentioned in the benchmark definition. The tests use standard JavaScript syntax for arithmetic operations. **Other considerations:** When choosing a library, consider factors such as: * Performance requirements * Precision needs * Support for various operations (e.g., addition, subtraction, multiplication, division) * Memory usage and potential impact on performance **Alternative approaches:** If none of these libraries suit your specific use case, you may want to explore other options, such as: 1. `Fraction.js`: A library for performing arithmetic with fractions. 2. Other custom implementations or specialized libraries (e.g., for financial calculations). Keep in mind that the choice of library ultimately depends on your specific requirements and constraints.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js vs. math.min.js
bignumber.js vs. big.js vs. decimal.js (without native)
number / bignumber.js / big.js / decimal.js
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?