Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test stefaf aasf
(version: 0)
Comparing performance of:
my vs BigNumber vs Native
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/bignumber.js@9.0.1/bignumber.min.js"></script>
Tests:
my
function plus(a, b) { let result = []; const aString = '' + a; const bString = '' + b; const aSplit = aString.split("."); const bSplit = bString.split("."); result[0] = [BigInt(aSplit[0]) + BigInt(bSplit[0])]; if(!aSplit[1]) { aSplit[1] = 0; } if(!bSplit[1]) { bSplit[1] = 0; } result[1] = [BigInt(aSplit[1]) + BigInt(bSplit[1])]; if(result[1] > 9) { result[0]++; result[1] = result[1] % 10; } return String(result.join('.')); } plus(0.1,0.3)
BigNumber
var a = new BigNumber("0.1"); var b = new BigNumber("0.2"); a.plus(b).toString();
Native
var a = 0.1; var b = 0.2; ((a + b) * b).toString();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
my
BigNumber
Native
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):
Measuring JavaScript performance is a crucial task, and BenchmarkThat.net provides an excellent platform for doing so. **Overview of the Benchmark** The provided benchmark tests three different approaches to perform simple arithmetic operations on decimal numbers: `my`, `BigNumber`, and `Native`. The goal is to compare their performance in executing these operations. **Options Compared** 1. **`my`**: This option uses a custom implementation, where the input numbers are split into string parts (before and after the decimal point), converted to BigInts, and then recombined with arithmetic operations. If the result of an operation exceeds 9, it is handled specially to ensure correct results. 2. **`BigNumber`**: This option uses the `bignumber.js` library, which provides a robust implementation for handling large and precise decimal numbers. The library's methods are used to add two BigNumbers together and then convert the result back to a string. 3. **`Native`**: This option uses native JavaScript arithmetic operations (addition and multiplication) directly on the numeric values. **Pros and Cons** 1. **`my`**: * Pros: Custom implementation allows for fine-grained control over the arithmetic logic, potentially leading to more efficient code. * Cons: The custom approach introduces additional complexity and may not be as performant as other options due to string manipulation and conversion between BigInts. 2. **`BigNumber`**: * Pros: Library provides a robust implementation for handling large decimal numbers, ensuring precision and reliability. * Cons: Additional overhead due to the library's existence and its method calls may impact performance. 3. **`Native`**: * Pros: Simple and straightforward approach using native JavaScript operations, likely to be more performant than custom implementations or library-based approaches. * Cons: Limited control over arithmetic logic and potential issues with precision or overflow handling. **Library Usage (BigNumber)** The `bignumber.js` library is used in the `BigNumber` option. Its primary purpose is to provide a robust implementation for handling large and precise decimal numbers, ensuring accurate results even when dealing with very large inputs. The library's methods are designed to handle arithmetic operations on these numbers efficiently. **Special JavaScript Feature (BigInt)** The custom implementation in the `my` option uses BigInts, which is a relatively new feature introduced in ECMAScript 2019 (ES10). BigInts allow for representing integers of arbitrary size, enabling precise arithmetic operations on very large and complex numbers. The use of BigInts in this benchmark allows for comparing different approaches to handling decimal numbers with high precision. **Alternatives** Other alternatives that could be explored in a performance benchmark include: * Using `decimal.js` library instead of `bignumber.js` * Implementing custom arithmetic logic using bitwise operations or other low-level techniques * Comparing performance with other programming languages, such as C++ or Rust * Investigating the impact of different hardware configurations (e.g., GPU acceleration) on JavaScript arithmetic performance Keep in mind that each alternative will introduce new variables and complexities, requiring careful consideration of their implications for the benchmark.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (no to string)
validate bignumber.js shiftedBy
validate bignumber.js big.js shiftedBy
bignumber.js vs. big.js vs. decimal.js (I)asd
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?