Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS BigInt big number performance vx4
(version: 10)
Compare Number vs BigInt for big numbers
Comparing performance of:
1 vs 2 vs 3 vs 4 vs 5 vs i256
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var bigInt1 = 9007199254740992n //MaxSafe +1 var bigInt2 = 103n var number1 = 9007199254740990 //MaxSafe -1 var number2 = 103 var pgMaxBigInt = 9223372036854775806n // 2^63-1 var pgDiv = 103n var pgDecimal = 92233720368547758070001230n // max digits before decimal point: 131072 var i128 = 17014118346046923173168730371588410572712345n //big var i128Div = 103n var i256 = 1701411834604692317316873037158841057271234517014118346046923173168730371588410572712345n //rlybig var i256Div = 103n
Tests:
1
a = bigInt1 b = bigInt2 c = a - b c = a % b c = a * b c = a + b
2
a = number1 b = number2 c = a - b c = a % b c = a * b c = a + b
3
a = pgMaxBigInt b = pgDiv c = a - b c = a % b c = a * b c = a + b
4
a = i128 b = i128Div c = a - b c = a % b c = a * b c = a + b
5
a = i128 b = i128Div c = a - b c = a % b c = a * b c = a + b
i256
a = i256 b = i256Div c = a - b c = a % b c = a * b c = a + b
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
1
2
3
4
5
i256
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
19 hours ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 147 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
1
503756.7 Ops/sec
2
503423.4 Ops/sec
3
473373.0 Ops/sec
4
445748.6 Ops/sec
5
428018.4 Ops/sec
i256
422724.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of what is being tested on MeasureThat.net. **Benchmark Overview** The benchmark compares the performance of different data types in JavaScript for arithmetic operations (addition, subtraction, multiplication, and division) with large numbers. The test cases use various libraries and special features to ensure a comprehensive comparison. **Test Cases** There are six test cases: 1. **Number vs BigInt**: This is the primary test case that compares the performance of `Number` and `BigInt` data types for arithmetic operations. 2. **JavaScript Built-in Integers**: This test case uses JavaScript's built-in integers (`i128` and `i256`) to compare their performance with the `BigInt` data type. **Libraries Used** * **BigInt**: The `BigInt` function is used to create large integer values. It was introduced in ECMAScript 2019. * **Number**: The native `Number` data type is used for regular integers. **Special Features and Syntax** * **BigInt**: As mentioned earlier, the `BigInt` data type is used to create large integer values. Its syntax is `n` (e.g., `9007199254740992n`). Note that this syntax was only introduced in ECMAScript 2019, so older browsers may not support it. * **JavaScript Built-in Integers**: The `i128` and `i256` variables are used to represent large integers. These values are not standard JavaScript literals. **Comparison Options** The benchmark compares the performance of the following options: 1. **Number vs BigInt** 2. **JavaScript Built-in Integers (i128) vs BigInt** 3. **JavaScript Built-in Integers (i256) vs BigInt** These comparisons help determine which data type performs better for large arithmetic operations. **Pros and Cons of Different Approaches** * **Using Number**: Pros: widely supported by older browsers, easy to implement. Cons: limited range for large integers. * **Using BigInt**: Pros: suitable for very large integers, introduced in ECMAScript 2019. Cons: may not be supported by older browsers. * **JavaScript Built-in Integers (i128 and i256)**: Pros: suitable for large integers, part of the standard JavaScript engine. Cons: limited range compared to `BigInt`. **Other Considerations** * **Device and Browser**: The benchmark results are reported for a specific browser and device platform (Chrome 109 on Windows). Results may vary with other browsers or devices. * **Execution Frequency**: The benchmark measures executions per second, which can be influenced by factors like CPU frequency, memory allocation, and other system resources. Overall, this benchmark helps developers understand the performance differences between various data types in JavaScript for large arithmetic operations, making informed decisions about which data type to use depending on the specific requirements of their project.
Related benchmarks:
BigInt vs ParseInt
JS BigInt big number performance vx
parseInt vs Number BigInts
bignumber.js vs. big.js vs. decimal.js 2022 ver. (random) (no toFixed)
Comments
Confirm delete:
Do you really want to delete benchmark?