Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS BigInt big number performance
(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 = 5000000n var number1 = 1000000 var number2 = 5000000
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:
8 months ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0
Browser/OS:
Firefox 142 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
BigInt
0.0 Ops/sec
Number
9580393.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark. **What is being tested?** The benchmark compares the performance of two data types in JavaScript: `Number` and `BigInt`. Specifically, it tests the performance of arithmetic operations (`-`, `%`, `*`, `+`, and `**`) on large numbers represented as either `Number` or `BigInt`. **Options compared** There are two options being compared: 1. **Number**: The traditional JavaScript number type, which uses 64-bit floating-point representation. 2. **BigInt**: A relatively new data type introduced in ECMAScript 2020, designed to support arbitrarily large integers. **Pros and cons of each approach:** * **Number**: + Pros: Wide compatibility with existing JavaScript code, simple implementation. + Cons: Limited precision for very large numbers, potential performance issues due to floating-point arithmetic. * **BigInt**: + Pros: Supports arbitrarily large integers, precise arithmetic operations, and improved performance for large numbers. + Cons: Newer data type, may require changes to existing JavaScript code. **Library used** The benchmark uses the `BigInt` library, which is a polyfill that provides support for `BigInt` in older browsers that don't natively support it. This allows the benchmark to run on a wider range of environments. **Special JS feature or syntax** This benchmark doesn't explicitly use any special JavaScript features or syntax beyond what's required for testing the `Number` and `BigInt` data types. However, it's worth noting that modern JavaScript engines are optimized for performance and may take advantage of certain browser-specific features or optimizations. **Other alternatives** If you were to write a similar benchmark from scratch, you might consider using: 1. **Benchmarks like JSHint**: A popular testing tool specifically designed for testing JavaScript code. 2. **Benchmarking libraries like Benchmark.js**: Specialized libraries that provide more advanced benchmarking features and tools. Keep in mind that the specific implementation details may vary depending on your goals, requirements, and target audience. **Benchmark preparation code** The provided `Script Preparation Code` initializes variables with large numbers for both `Number` and `BigInt`, ensuring consistent test cases: ```javascript var bigInt1 = 1000000n; var bigInt2 = 5000000n; var number1 = 1000000; var number2 = 5000000; ``` **Individual test cases** The benchmark defines two individual test cases, each with a different approach: Test case 1: **BigInt** ```javascript a = bigInt1 b = bigInt2 c = a - b c = a % b c = a * b c = a + b c = a ** b ``` Test case 2: **Number** ```javascript a = number1 b = number2 c = a - b c = a % b c = a * b c = a + b c = a ** b ``` Both test cases perform the same arithmetic operations, but using `Number` and `BigInt`, respectively.
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?