Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Big Integers
(version: 2)
Comparing performance of:
JSBN vs SJCL BN vs BigInteger.js vs Leemon Baird BigInt
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="http://www-cs-students.stanford.edu/~tjw/jsbn/jsbn.js"></script> <script src="http://www-cs-students.stanford.edu/~tjw/jsbn/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 src="http://www.leemon.com/crypto/BigInt.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);
Leemon Baird BigInt
a = str2bigInt(n1, 16, 0); b = str2bigInt(n2, 16, 0); c = sub(a, b); c = mod(a, b); c = mult(a, b); c = add(a, b); c = powMod(a, str2bigInt(five, 10, 0), 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
Leemon Baird BigInt
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmarking test suite, specifically designed to compare the performance of different libraries for working with large integers in JavaScript. **Libraries Compared** Four libraries are compared in this benchmark: 1. **JSBN (JavaScript Big Number)**: A lightweight library developed by TJ Crowder, providing support for arbitrary-precision arithmetic. 2. **SJCL BN**: A part of the SJCL (Secure JavaScript Compiler) project, providing a secure big integer implementation. 3. **BigInteger.js**: A library developed by Peter Olson, offering support for large integers with various algorithms. 4. **Leemon Baird BigInt**: A lightweight library optimized for performance and simplicity. **Options Compared** The benchmark compares different operations on large integers: * **Subtraction (`c = a.subtract(b)`)**: Calculates the difference between two large integers. * **Modulus (`c = a.mod(b)`)**: Computes the remainder of dividing one large integer by another. * **Multiplication (`c = a.multiply(b)`)**: Multiplies two large integers together. * **Addition (`c = a.add(b)`)**: Adds two large integers together. * **Modular exponentiation (`c = a.modPow(new BigInteger(five), b)`)**: Calculates the result of raising one large integer to the power of another, using modular arithmetic. **Pros and Cons of Each Approach** Each library has its strengths and weaknesses: * **JSBN**: Lightweight and easy to use, but may not be as efficient as other libraries for very large integers. * **SJCL BN**: Provides a secure implementation, but may have overhead due to its security features. * **BigInteger.js**: Offers a wide range of algorithms for large integer operations, but may be slower than others. * **Leemon Baird BigInt**: Optimized for performance and simplicity, making it suitable for applications where speed is crucial. **Special Considerations** The benchmark uses some special JavaScript features: * `new BigInteger()` (JSBN): Creates a new big integer object from a string or number. * `sjcl.bn` (SJCL BN): Creates a new secure big integer object from a string or number. * `bigInt()` (BigInteger.js): Creates a new big integer object from a string or number. * `str2bigInt()` (Leemon Baird BigInt): Converts a string to a big integer. **Other Alternatives** For large integers, other JavaScript libraries and implementations exist, such as: * **Mathematica**: A powerful computational engine for mathematics and arbitrary-precision arithmetic. * **NumJS**: A JavaScript library providing support for numerical computations, including large integers. * **BigIntify**: A lightweight library offering support for large integers with various algorithms. Keep in mind that this benchmark is focused on comparing the performance of specific libraries and implementations, rather than evaluating their overall quality or suitability for a particular use case.
Related benchmarks:
bignumber.js vs. big.js apr
bignumber.js vs. big.js vs. decimal.js (I)asd
bigint vs. bignumber.js vs. big.js vs. decimal.js
bigint vs. bignumber.js vs. big.js vs. decimal.js with exponentiation
bigint vs. bignumber.js vs. big.js vs. break_infinity.js
Comments
Confirm delete:
Do you really want to delete benchmark?