Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
decimal.js vs. Fraction.js
(version: 0)
Comparing performance of:
Native vs Native + toFixed vs decimal.js vs Fraction.js
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/decimal.js@10.2.0/decimal.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fraction.js@4.0.12/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();
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 (4)
Previous results
Fork
Test case name
Result
Native
Native + toFixed
decimal.js
Fraction.js
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Android 12; Mobile; rv:147.0) Gecko/147.0 Firefox/147.0
Browser/OS:
Firefox Mobile 147 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
585634816.0 Ops/sec
Native + toFixed
8326149.0 Ops/sec
decimal.js
582912.6 Ops/sec
Fraction.js
946993.7 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 benchmark compares the performance of two libraries: `decimal.js` and `Fraction.js`. The test cases evaluate how fast each library can perform arithmetic operations on decimal numbers. **Test Cases** There are four test cases: 1. **Native**: This test case evaluates the native JavaScript implementation of adding and multiplying two decimal numbers, then converting the result to a string using the `toString()` method or the `toFixed(9)` method. 2. **Native + toFixed**: Similar to the previous test case, but uses the `toFixed(9)` method instead of `toString()`. 3. **decimal.js**: This test case uses the `Decimal` class from the `decimal.js` library to perform arithmetic operations on decimal numbers. The `plus`, `times`, and `toString` methods are used. 4. **Fraction.js**: Similar to the previous test case, but uses the `Fraction` class from the `Fraction.js` library to perform arithmetic operations on fractional numbers. **Options Compared** The two libraries being compared are: * `decimal.js`: A JavaScript implementation of decimal arithmetic. * `Fraction.js`: A JavaScript implementation of fraction arithmetic. **Pros and Cons** Here's a brief overview of the pros and cons of each library: * **decimal.js**: + Pros: - High-performance implementation - Supports many decimal operations (e.g., addition, subtraction, multiplication, division) - Allows for precise control over rounding and formatting + Cons: - Can be complex to use, especially for advanced users - Not as widely supported as some other libraries * **Fraction.js**: + Pros: - Simple and easy to use - Supports basic fraction operations (e.g., addition, subtraction, multiplication) - Has a small footprint and is easy to integrate into existing projects + Cons: - May not be as efficient as `decimal.js` for complex arithmetic operations - Limited functionality compared to `decimal.js` **Other Considerations** When choosing between these two libraries, consider the following factors: * **Precision**: If you need high precision and control over rounding, `decimal.js` might be a better choice. If you're working with simple fractions or don't require precise control, `Fraction.js` could be sufficient. * **Performance**: If speed is critical, `decimal.js` is likely to outperform `Fraction.js`. * **Ease of use**: If simplicity and ease of use are more important than raw performance, `Fraction.js` might be a better fit. **Library Descriptions** 1. **decimal.js**: A JavaScript library for decimal arithmetic. It provides a robust implementation of decimal operations, including addition, subtraction, multiplication, division, and rounding. 2. **Fraction.js**: A lightweight JavaScript library for working with fractions. It allows users to create and manipulate fraction objects, performing basic arithmetic operations like addition and multiplication. **Special JS Features or Syntax** There are no special JS features or syntax mentioned in the benchmark that require explanation.
Related benchmarks:
decimal.js vs. Fraction.js (no native)
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9)
decimal.js vs. native
bignumber.js vs. big.js vs. decimal.js vs. math.min.js
Native.toFixed() vs bignumber.js vs big.js vs decimal.js
Comments
Confirm delete:
Do you really want to delete benchmark?