Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS BigInt big number performance v2
(version: 0)
Compare Number vs BigInt for big numbers
Comparing performance of:
BigInt vs Number
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var bigInt1 = 1000000n var bigInt2 = 50n var number1 = 1000000 var number2 = 50
Tests:
BigInt
a = bigInt1 b = bigInt2 c = a - b c = a % b c = a * b c = a + b c = a ** b
Number
a = number1 b = number2 c = a - b c = a % b c = a * b c = a + b c = a ** b
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
BigInt
Number
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
BigInt
537339.9 Ops/sec
Number
487917.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares the performance of two data types: `Number` and `BigInt`. Specifically, it measures the execution time of various arithmetic operations (addition, subtraction, multiplication, division, exponentiation) on both data types for large numbers. **Options compared** Two options are being compared: 1. **Number**: The traditional JavaScript number type. 2. **BigInt**: A relatively new data type introduced in ECMAScript 2020, designed to support arbitrary-precision integers. **Pros and Cons of each approach:** * **Number**: + Pros: - Wide browser support - Simple implementation (no need for additional libraries) + Cons: - Limited precision, which can lead to rounding errors and performance issues with very large numbers. - May exhibit slower performance due to the need for approximation or rounding. * **BigInt**: + Pros: - Arbitrary-precision support, eliminating rounding errors and potential performance bottlenecks. - Designed specifically for high-performance arithmetic operations on large integers. + Cons: - Requires support from modern browsers (Chrome 129 and above) and engines (e.g., V8 in Chrome). - May require additional libraries or workarounds for older browsers. **Library usage** The benchmark uses the `BigInt` library to create and manipulate `BigInt` values. However, since this is a built-in JavaScript feature starting from ECMAScript 2020, no external library is necessary. **Special JS feature or syntax** The test cases utilize the `n` suffix for BigInt literals, introduced in ECMAScript 2019. This allows you to create arbitrary-precision integers without needing additional libraries or workarounds. **Other alternatives** If a browser does not support `BigInt`, you might consider using: 1. Third-party libraries like `big.js` or `decimal.js` that provide similar arithmetic capabilities. 2. Other data types, such as strings or arrays of integers, for smaller numbers. 3. Using a different language or runtime environment that supports arbitrary-precision integers. Keep in mind that each alternative has its own trade-offs and requirements, so the choice depends on your specific use case and constraints.
Related benchmarks:
JS BigInt multiply vs addition
BigInt vs ParseInt
JS BigInt big number performance vx
JS BigInt big number performance vx4
parseInt vs Number BigInts
Comments
Confirm delete:
Do you really want to delete benchmark?