Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
decimal.js vs. native reduce
(version: 0)
- https://github.com/MikeMcl/decimal.js/tree/v10.3.1
Comparing performance of:
Native vs decimal.js
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.3.1/decimal.min.js"></script>
Tests:
Native
[1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212].reduce((a, b) => a + b, 0)
decimal.js
[1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212, 1, 2, 3, 4, .2, .1, .5, .1, .0981212].reduce( (a, b) => a.plus(b), new Decimal(0) ).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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
60574112.0 Ops/sec
decimal.js
117744.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks. **Overview** The provided JSON represents a benchmark test that compares the performance of two approaches: using native `reduce()` method and using the `Decimal` library with its `plus()` method. **What is being tested?** In this case, we are testing the performance of reducing an array of decimal numbers. The array contains both integer and decimal values. **Options compared** Two options are compared: 1. **Native Reduce**: This option uses the native `reduce()` method to add up all the elements in the array. 2. **Decimal.js**: This option uses the `Decimal` library to perform arithmetic operations on decimal numbers. Specifically, it uses the `plus()` method to add two decimals together and returns a new `Decimal` object. **Pros and Cons** **Native Reduce:** * Pros: + Built-in JavaScript function with good performance. + No additional dependencies required. * Cons: + May not handle decimal operations correctly due to floating-point arithmetic issues. + Can be slower for large datasets due to overhead of JavaScript engine. **Decimal.js:** * Pros: + Provides a robust and accurate way to perform decimal arithmetic. + Handles decimal operations correctly, reducing the risk of rounding errors. * Cons: + Requires an additional dependency (the `decimal.js` library). + May introduce additional overhead due to the creation of new objects. **Other considerations** The benchmark results show that the native `reduce()` method is significantly faster than using the `Decimal` library. However, this may not be representative for all use cases, as the performance difference may vary depending on the specific requirements and constraints of the application. **Library description** The `decimal.js` library is a popular JavaScript library for working with decimal numbers. It provides a robust and accurate way to perform arithmetic operations on decimal numbers, including addition, subtraction, multiplication, and division. The library also handles rounding and other edge cases correctly. The library returns objects that can be used in various ways, such as converting them to strings or integers, adding a specific precision level, etc. **Special JS features** This benchmark does not use any special JavaScript features or syntax beyond the standard `reduce()` method and `Decimal` library functions.
Related benchmarks:
Add using Decimal.js vs Add using native numbers
Add using Decimal.js vs native JS vs Number() vs parseFloat()
Multiply using Decimal.js vs Multiply using native numbers vs exactMath 1
Decimal.js vs native subtract vs native localeCompare
Comments
Confirm delete:
Do you really want to delete benchmark?