Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Big Integers v3
(version: 0)
Comparing performance of:
JSBN vs SJCL BN vs BigInteger.js vs native BigInt
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://burak.fr/jsbn.js"></script> <script src="https://burak.fr/jsbn2.js"></script> <script src="https://rawgit.com/bitwiseshiftleft/sjcl/master/sjcl.js"></script> <script src="https://rawgit.com/bitwiseshiftleft/sjcl/master/core/bn.js"></script> <script src="https://rawgit.com/peterolson/BigInteger.js/master/BigInteger.min.js"></script>
Script Preparation code:
var n1 = "f10853b38e67ed882bc0284b8e71581469806699e8a028a19cd8cac913a3f8b859ee0999833886f13987ecf4ed3a11cf6aabd0b074531f5ef338f624e62429ff"; var n2 = "d978cfde1678dc8ce9dab4bfe2e1fa8be09a5668cd8e607cc24f28e440495c7f4b5317d6533e3fb232ebce63fab872ece25935a5cacc5cb8a94b5"; var five = "5";
Tests:
JSBN
a = new BigInteger(n1, 16); b = new BigInteger(n2, 16); c = a.subtract(b); c = a.mod(b); c = a.multiply(b); c = a.add(b); c = a.modPow(new BigInteger(five), b);
SJCL BN
a = new sjcl.bn(n1); b = new sjcl.bn(n2); c = a.sub(b); c = a.mod(b); c = a.mul(b); c = a.add(b); c = a.powermod(new sjcl.bn(five), b);
BigInteger.js
a = bigInt(n1, 16); b = bigInt(n2, 16); c = a.subtract(b); c = a.mod(b); c = a.multiply(b); c = a.add(b); c = a.modPow(bigInt(five), b);
native BigInt
a = BigInt('0x' + n1); b = BigInt('0x' + n2); c = a - b; c = a % b; c = a * b; c = a + b; c = a ** BigInt(five) % b;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
JSBN
SJCL BN
BigInteger.js
native BigInt
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSBN
0.0 Ops/sec
SJCL BN
2700.7 Ops/sec
BigInteger.js
27982.2 Ops/sec
native BigInt
86294.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of different JavaScript libraries for big integer arithmetic can be a challenging task. **Benchmark Overview** The benchmark measures the execution speed of four different approaches for performing big integer operations: 1. Native BigInt 2. BigInteger.js 3. SJCL BN (Simple Java Cryptography Library for Browser) 4. JSBN (JavaScript Big Number) Each test case uses a specific script preparation code, which includes two large numbers (`n1` and `n2`) in hexadecimal format, and another number (`five`) as a string. **Options Compared** The benchmark compares the performance of each library by executing different operations on the two large numbers: * Subtracting * Modulo (remainder) * Multiplying * Addition * Modulo power (exponentiation) **Pros and Cons of Each Approach** 1. **Native BigInt**: This approach uses the built-in JavaScript `BigInt` data type, which is supported in modern browsers. * Pros: Fast and efficient, no external dependencies. * Cons: Limited functionality compared to other libraries, may not be available in older browsers. 2. **BigInteger.js**: This library provides a comprehensive implementation of big integer arithmetic. * Pros: Wide range of operations supported, easy to use, reliable. * Cons: May have performance overhead due to the complexity of its implementation. 3. **SJCL BN**: This library is designed for secure cryptographic applications and provides a fast and efficient implementation of big integer arithmetic. * Pros: Fast and efficient, suitable for cryptographic applications. * Cons: May not be as widely supported as other libraries, has a steeper learning curve. 4. **JSBN**: This library is a simple implementation of big integer arithmetic, but may have performance limitations due to its simplicity. * Pros: Lightweight and easy to use, suitable for basic applications. * Cons: Limited functionality compared to other libraries, may not be as fast. **Library Overview** 1. **BigInteger.js**: This library provides a comprehensive implementation of big integer arithmetic, including operations like addition, subtraction, multiplication, division, exponentiation, and more. It also includes features like modular inverses and prime factorization. 2. **SJCL BN**: This library is designed for secure cryptographic applications and provides a fast and efficient implementation of big integer arithmetic. It includes features like modular exponentiation and digital signatures. 3. **JSBN**: This library provides a simple implementation of big integer arithmetic, including operations like addition, subtraction, multiplication, and exponentiation. **Special JavaScript Features or Syntax** The benchmark uses the `BigInt` data type, which was introduced in ECMAScript 2017. It also uses the `String.prototype.startsWith()` method to compare strings, but this is not specific to big integer arithmetic. **Alternatives** Other alternatives for big integer arithmetic libraries include: 1. **Mathjs**: A JavaScript library that provides a comprehensive implementation of mathematical operations, including big integer arithmetic. 2. **GMP.js**: A JavaScript library that provides an implementation of the GNU Multiple Precision Arithmetic Library (GMP), which is widely used in cryptographic applications. In conclusion, the benchmark provides a good overview of the performance of different libraries for big integer arithmetic, and can help developers choose the most suitable library for their specific use case.
Related benchmarks:
JS Big Integers
JS Big Integers v2
bignumber.js vs. big.js vs. decimal.js (I) vs currencyjs
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?