Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
(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
(211555240.22).toFixed(9);
decimal.js
var a = new Decimal("211555240.22"); a.toFixed(9);
big.js
var a = new Big("211555240.22"); a.toFixed(9);
bignumber.js
var a = new BigNumber("211555240.22"); a.toFixed(9);
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:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
20450650.0 Ops/sec
decimal.js
2925602.5 Ops/sec
big.js
3866934.5 Ops/sec
bignumber.js
2168058.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark that compares the performance of three libraries: bignumber.js, big.js, and decimal.js, when rounding a large number to nine decimal places. **What is being tested?** The test case uses a simple mathematical operation: `toFixed(9)`. This method rounds a number to the specified number of decimal places. The test compares the performance of three libraries: 1. **Native**: JavaScript's built-in `toFixed` method. 2. **decimal.js**: A library specifically designed for precise arithmetic and rounding. 3. **big.js** and **bignumber.js**: Libraries that provide support for arbitrary-precision arithmetic. **Options compared** The test compares the following options: * Native (JavaScript's built-in `toFixed` method) * decimal.js * big.js * bignumber.js Each option is tested with a different input: a large number rounded to nine decimal places (`211555240.22`). **Pros and Cons of each approach** 1. **Native**: JavaScript's built-in `toFixed` method is a good choice when performance is critical, but it may not provide the desired level of precision for large numbers. * Pros: Lightweight, easy to use * Cons: May not be suitable for large numbers, can lead to rounding errors 2. **decimal.js**: This library provides precise arithmetic and rounding, making it a good choice when accuracy is crucial. * Pros: Provides high accuracy, supports arbitrary-precision arithmetic * Cons: Can be slower than native methods due to the additional overhead of arithmetic operations 3. **big.js** and **bignumber.js**: These libraries provide support for arbitrary-precision arithmetic, making them suitable for large numbers. * Pros: Provides high accuracy, supports large numbers * Cons: Can be heavier-weight than native methods, may require more memory **Library descriptions** 1. **decimal.js**: A library designed for precise arithmetic and rounding, providing a safe way to perform calculations with decimal numbers. 2. **big.js**: A library that provides support for arbitrary-precision arithmetic, making it suitable for large numbers. 3. **bignumber.js**: A library that provides support for arbitrary-precision arithmetic, similar to big.js. **Special JavaScript features** This benchmark does not explicitly use any special JavaScript features or syntax. However, the use of libraries like decimal.js, big.js, and bignumber.js demonstrates the importance of choosing the right tools for the job, especially when dealing with large numbers or precise calculations. **Alternatives** If you need to perform large-scale numerical computations, other alternatives to these libraries include: 1. **BigInt**: A built-in JavaScript function that provides support for arbitrary-precision integers. 2. **Libraries like Mathjs** or **PLplot.js**, which provide high-performance arithmetic and graphics capabilities. However, keep in mind that the performance and accuracy of these alternatives may vary depending on your specific use case and requirements.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js vs. math.min.js
bignumber.js vs. big.js vs. decimal.js only calculation without toString()
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?