Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Big Integers v2
(version: 0)
Comparing performance of:
JSBN vs SJCL BN vs BigInteger.js vs native BigInt
Created:
5 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://rawgithub.com/bitwiseshiftleft/sjcl/master/sjcl.js"></script> <script src="https://rawgithub.com/bitwiseshiftleft/sjcl/master/core/bn.js"></script> <script src="https://rawgithub.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:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSBN
0.0 Ops/sec
SJCL BN
3129.4 Ops/sec
BigInteger.js
47949.7 Ops/sec
native BigInt
472744.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark JSON and explain what's being tested, the different approaches compared, their pros and cons, and other considerations. **Benchmark Overview** The `JS Big Integers v2` benchmark tests the performance of various JavaScript libraries for performing arithmetic operations on large integers. The test cases use different libraries to perform basic arithmetic operations like addition, subtraction, multiplication, division, and exponentiation on two large integers. **Library Descriptions and Purposes** 1. **jsbn.js**: A lightweight library for working with arbitrary-precision numbers in JavaScript. 2. **BigInteger.js**: A library for performing arithmetic operations on large integers in JavaScript. It provides a `BigInteger` class that allows you to create and manipulate large integers. 3. **sjcl.bn**: A module from the SecureJSCL (Secure JavaScript Cryptography Library) that provides support for arbitrary-precision numbers. **Approaches Compared** The benchmark tests four different approaches: 1. **native BigInt**: Uses the built-in `BigInt` primitive in JavaScript to perform arithmetic operations on large integers. 2. **BigInteger.js**: Uses the `BigInteger` class from the BigInteger.js library to perform arithmetic operations on large integers. 3. **SJCL BN**: Uses the `bn` module from the SecureJSCL (Secure JavaScript Cryptography Library) to perform arithmetic operations on large integers. 4. **jsbn.js**: Uses the lightweight jsbn.js library to perform arithmetic operations on large integers. **Pros and Cons of Each Approach** 1. **native BigInt**: * Pros: Built-in support, efficient performance, no dependencies required. * Cons: Limited functionality compared to other libraries, may not be compatible with older browsers. 2. **BigInteger.js**: * Pros: Robust feature set, well-maintained library, suitable for most use cases. * Cons: Larger size and complexity compared to native BigInt, may require additional dependencies. 3. **SJCL BN**: * Pros: Highly optimized performance, secure implementation, part of a trusted cryptography library. * Cons: Limited functionality compared to other libraries, requires SecureJSCL as a dependency. 4. **jsbn.js**: * Pros: Lightweight and compact, easy to integrate into projects. * Cons: May not offer the same level of functionality as other libraries, limited documentation. **Other Considerations** * The benchmark results are influenced by the device platform (Mobile or Desktop), browser version (Firefox 130), and operating system (Android). * The `ExecutionsPerSecond` metric indicates how many operations are performed per second, which is a good indicator of performance. * The test cases cover basic arithmetic operations, but other libraries may offer additional features like modular inverses or prime factorization. **Alternatives** If you're interested in exploring alternative libraries for large integer arithmetic in JavaScript, some notable options include: 1. **Big-JavaScript**: A library that provides a `BigInteger` class with support for various arithmetic operations. 2. **Arbitrary-precision arithmetic libraries like GNU Multiple Precision Arithmetic Library (GMP) or MPFR**. While not specifically designed for JavaScript, these libraries can be used as a backend for JavaScript projects. Keep in mind that each library has its strengths and weaknesses, and the choice ultimately depends on your specific project requirements and constraints.
Related benchmarks:
JS Big Integers
validate bignumber.js big.js shiftedBy
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?