Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS BigInt big number performance v12
(version: 0)
Compare Number vs BigInt for big numbers
Comparing performance of:
BigInt vs Number
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var bigInt1 = 1000000n var bigInt2 = 10n var number1 = 1000000 var number2 = 10
Tests:
BigInt
a = bigInt1; b = bigInt2; for(let i = 0; i < 1000; ++i) { c = a << b; c = a | b; c = a ^ b; }
Number
a = number1 b = number2 for(let i = 0; i < 1000; ++i) { 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:
an hour ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
BigInt
1434.8 Ops/sec
Number
1711.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** The benchmark compares the performance of using `Number` versus `BigInt` data types for large numbers in JavaScript. The test case uses a simple loop that performs bitwise operations (`<<`, `|`, and `^`) on two large numbers. **Options compared:** 1. **Number**: Using regular JavaScript numbers, which are represented as 64-bit floating-point numbers. 2. **BigInt**: A relatively new data type in JavaScript (introduced in ECMAScript 2020) that represents arbitrarily large integers. **Pros and Cons:** * **Number**: * Pros: Widely supported across browsers, easy to use, and doesn't require any specific syntax changes. * Cons: Limited precision for very large numbers, can lead to performance issues due to floating-point arithmetic. * **BigInt**: * Pros: Offers arbitrary-precision integer arithmetic, allowing for precise calculations with very large numbers. * Cons: Requires the use of `n` suffix (e.g., `1000000n`) to indicate BigInt literals, which can be unfamiliar to some developers. **Other considerations:** * **Browser support**: Both options are widely supported in modern browsers. However, older browsers might not support `BigInt`. * **Performance impact**: The test case measures the performance of bitwise operations on large numbers. In general, `BigInt` is expected to perform better than `Number` due to its arbitrary-precision arithmetic capabilities. **Library usage:** None mentioned in this benchmark definition. **Special JS features or syntax:** None mentioned in this benchmark definition. **Benchmark preparation code explanation:** The script prepares two large numbers (`bigInt1`, `bigInt2`) and two regular numbers (`number1`, `number2`). The test loop then performs bitwise operations on these pairs of numbers using the `<<`, `|`, and `^` operators. The benchmark definition specifies that the test cases use these specific values. **Individual test case explanations:** The two individual test cases are identical, except for the data type used to represent the large numbers: 1. **BigInt**: The first test case uses `BigInt` literals with the `n` suffix (`1000000n`, `10n`). It measures the performance of bitwise operations on these BigInt values. 2. **Number**: The second test case uses regular JavaScript numbers (`1000000`, `10`) and measures their performance in comparison to the first test case. **Latest benchmark result explanation:** The latest benchmark results show that: * The Chrome 121 browser running on a Linux desktop performs better for the `Number` option, with an average of 1139.66 executions per second. * The Chrome 121 browser running on a Linux desktop also performs better for the `BigInt` option, but at a slower rate than the `Number` option (average of 1208.12 executions per second). Keep in mind that these results might vary depending on the specific hardware and software environment. **Other alternatives:** Some alternative approaches to benchmarking JavaScript performance could include: * Using other data types like `BigInt` or `Number` with different precision options. * Implementing custom arithmetic operations for large numbers using a library or by rewriting the test cases in AssemblyScript or another low-level language. * Utilizing parallel processing or multi-threaded execution to measure performance on multicore systems. However, these alternatives might require additional setup and expertise.
Related benchmarks:
JS BigInt multiply vs addition
BigInt vs ParseInt
JS BigInt big number performance vx4
bignumber.js vs native benchmark: compareTo
parseInt vs Number BigInts
Comments
Confirm delete:
Do you really want to delete benchmark?