Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
decimal.js vs. native
(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
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; a + b
decimal.js
var a = new Decimal("0.1"); a.plus(.2).toNumber();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
decimal.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
13 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
315355648.0 Ops/sec
decimal.js
3523366.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **What is being tested?** The benchmark compares the performance of three libraries: `bignumber.js`, `big.js`, and `decimal.js` for performing arithmetic operations on decimal numbers. Specifically, two test cases are used: 1. The native JavaScript implementation (i.e., without using any library) to add two decimal numbers. 2. Each library's implementation to add the same two decimal numbers. **Options being compared** The options being compared are the performance of each library when performing arithmetic operations on decimal numbers. This includes the execution speed, which is measured in executions per second (EPs/s). **Pros and cons of different approaches:** 1. **Native JavaScript implementation:** This approach has no overhead due to external libraries, but it may not be as efficient or accurate as using a specialized library for decimal arithmetic. * Pros: No additional dependencies or complexity. * Cons: May not provide the same level of accuracy or performance as specialized libraries. 2. **bignumber.js implementation:** This library is designed specifically for high-precision arithmetic and has a reputation for being fast and accurate. * Pros: High-performance and accurate arithmetic operations. * Cons: Additional dependency and potential complexity. 3. **big.js implementation:** Another popular library for decimal arithmetic, big.js is known for its simplicity and performance. * Pros: Fast and efficient arithmetic operations with minimal overhead. * Cons: May not be as accurate as bignumber.js. **Library overview:** 1. **bignumber.js**: Developed by Mike McLean, this library provides high-precision arithmetic operations and is designed to be fast and accurate. It uses the `Decimal` class to represent decimal numbers and offers various methods for performing arithmetic operations. 2. **big.js**: Also known as "Big" (not to be confused with bignumber.js), this library was developed by Paul Rossetti and provides high-performance decimal arithmetic operations using the `Big` constructor. 3. **decimal.js**: This library is designed specifically for decimal arithmetic and offers a simple, intuitive API for performing arithmetic operations. **Special JavaScript features or syntax:** The benchmark uses standard JavaScript syntax, without any special features or syntax that would be specific to recent ECMAScript standards (e.g., ES2015+). **Considerations:** When choosing a library for decimal arithmetic, consider the trade-offs between performance, accuracy, and complexity. If high-performance and accuracy are essential, bignumber.js might be the best choice. However, if simplicity and ease of use are more important, big.js or decimal.js could be suitable options. **Alternatives:** Other alternatives to these libraries include: * **Fraction.js**: A library for rational arithmetic that provides a different approach to decimal arithmetic. * **JS-Bigint**: A library for arbitrary-precision integer arithmetic, which can also be used for decimal arithmetic with some workarounds. * **decimal-fraction.js**: A lightweight library for rational arithmetic that is designed for use in web applications. Keep in mind that this benchmark only compares the performance of these three libraries, so it's essential to consider your specific requirements and evaluate other libraries if needed.
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 (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?