Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sdfsdf424234234222
(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).multipliedBy(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 the performance of different approaches to calculate the sum of two decimal numbers is an interesting benchmark. The provided JSON contains three test cases, each representing a different method to calculate the sum: 1. **"my"`**: This test case uses a custom implementation in JavaScript, specifically designed for this benchmark. It takes two decimal numbers as input, converts them to strings, splits them into parts (assuming only one part if no dot is present), and then performs the addition and handling of carry-over (if necessary). The result is returned as a string. **Pros:** - Custom implementation tailored to this specific benchmark - May be optimized for performance **Cons:** - Hardcoded and may not work with all decimal numbers or edge cases - Not a standard JavaScript method, which might make it less familiar to some developers 2. **"BigNumber"`**: This test case uses the `BigNumber` library from a CDN link. It creates two instances of `BigNumber`, performs addition using the `plus()` method, and then multiplies the result by one of the original numbers before converting everything back to a string. **Pros:** - Uses a widely-used and well-tested library (`BigNumber`) - Standard method in many financial applications **Cons:** - External dependency (the `BigNumber` library) might impact performance or availability - May be slower than custom implementations due to the overhead of the library 3. **"Native"`**: This test case uses only built-in JavaScript features, without any external libraries. It directly adds two decimal numbers and then converts the result back to a string. **Pros:** - No external dependencies or potential performance impact - Standard JavaScript method **Cons:** - May be slower than custom implementations due to parsing and conversion overhead - May have limitations with certain decimal formats or edge cases The benchmark compares these three approaches by measuring the execution speed of each test case. In general, when working with decimal numbers in JavaScript, using a library like `BigNumber` can provide an efficient and reliable way to handle complex calculations. However, for simple use cases, custom implementations might be more suitable due to their potential performance benefits. Other alternatives that could be explored include: * Using the `Decimal.js` library instead of `BigNumber` * Implementing a custom decimal arithmetic system from scratch * Utilizing specialized libraries or frameworks designed for financial calculations (e.g., `numjs`) * Leveraging hardware acceleration or optimized libraries for high-performance calculations When working with decimal numbers, it's essential to consider factors such as precision, rounding modes, and the chosen data type (e.g., `number`, `BigInt`) to ensure accurate results and optimal performance.
Related benchmarks:
bignumber.js vs. big.js vs. decimal.js (I) no native
validate bignumber.js shiftedBy
validate bignumber.js big.js shiftedBy
bignumber.js vs. big.js vs. decimal.js in 2024-05-03
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?