Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sha256-js
(version: 0)
Comparing performance of:
forge vs native vs sjcl vs crypto vs cryptico
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.6/sjcl.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/cryptico/0.0.1343522940/cryptico.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.9.1/forge.min.js"></script>
Script Preparation code:
var data = new Uint32Array(1024); window.crypto.getRandomValues(data); var dataBuffer = new Uint8Array(data); data = String.fromCharCode.apply(null, dataBuffer); // src: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest function hex(buffer) { var hexCodes = []; var view = new DataView(buffer); for (var i = 0; i < view.byteLength; i += 4) { // Using getUint32 reduces the number of iterations needed (we process 4 bytes each time) var value = view.getUint32(i) // toString(16) will give the hex representation of the number without padding var stringValue = value.toString(16) // We use concatenation and slice for padding var padding = '00000000' var paddedValue = (padding + stringValue).slice(-padding.length) hexCodes.push(paddedValue); } // Join all the hex strings into one return hexCodes.join(""); }
Tests:
forge
forge.md.sha256.create().update(data).digest()
native
crypto.subtle.digest("SHA-256", dataBuffer ).then(function (hash) {console.log(hex(hash));});
sjcl
sjcl.hash.sha256.hash(data);
crypto
CryptoJS.SHA256(data);
cryptico
SHA256(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
forge
native
sjcl
crypto
cryptico
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
forge
33576.7 Ops/sec
native
293067.5 Ops/sec
sjcl
10326.1 Ops/sec
crypto
11440.4 Ops/sec
cryptico
2094.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll do my best to explain the benchmarking process and options compared in this JSON data. **Overview** The provided JSON represents a JavaScript microbenchmarking test, which measures the performance of different libraries for calculating the SHA-256 hash of a given input data. The test consists of four individual benchmark cases: `forge`, `native`, `sjcl`, and `crypto`. **Script Preparation Code** The script preparation code is responsible for generating random data for the benchmark. It creates a 1024-element array of unsigned integers (`Uint32Array`) using the Web Crypto API's `getRandomValues` method, converts it to a binary string (`dataBuffer`), and then converts this binary string to a character array (`data`) using `String.fromCharCode.apply(null, dataBuffer)`. **Benchmark Cases** Each benchmark case uses a different library or implementation to calculate the SHA-256 hash of the prepared data. Here's an overview of each case: 1. **Forge**: The "forge" benchmark case uses the Forge.js library, which is a JavaScript cryptographic toolkit. It creates a new SHA-256 instance using `forge.md.sha256.create()`, updates it with the prepared data, and then calls the `digest()` method to get the hash. 2. **Native**: The "native" benchmark case uses the Web Crypto API's `digest` function to calculate the SHA-256 hash directly on the browser's native platform. It takes a binary string (`dataBuffer`) as input and passes it to the `digest` function with the algorithm parameter set to `"SHA-256"`. 3. **Sjcl**: The "sjcl" benchmark case uses the SJCL (Secure JavaScript Cryptography Library) library, which provides various cryptographic primitives, including hash functions. It calls the `hash()` method on the SHA-256 instance created by SJCL. 4. **Crypto**: The "crypto" benchmark case uses the CryptoJS library, which is a popular JavaScript cryptography library. It calls the `SHA256()` function on the prepared data to get the hash. **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: * **Forge**: Pros: well-maintained, feature-rich cryptographic toolkit; Cons: might be overkill for simple hashing tasks. * **Native**: Pros: uses native platform for calculations, reducing overhead; Cons: requires Web Crypto API support, which might not be available in older browsers. * **Sjcl**: Pros: compact, lightweight library with a focus on security; Cons: less extensive than other libraries, might lack certain features. * **Crypto**: Pros: widely used, feature-rich library with a large community; Cons: larger size compared to Sjcl, might be slower due to additional overhead. **Other Considerations** When choosing a hashing library or implementation, consider factors such as: * Security requirements * Performance needs (speed and throughput) * Compatibility with different browsers and platforms * Code size and complexity **Alternatives** If you're looking for alternative libraries or implementations for SHA-256 hashing in JavaScript, some popular options include: * OpenSSL.js: A JavaScript wrapper around the OpenSSL library. * WebCrypto: The Web Crypto API itself, which provides a set of cryptographic primitives, including hash functions. In conclusion, this benchmarking test compares the performance of different JavaScript libraries and implementations for calculating the SHA-256 hash. Each approach has its pros and cons, and the choice ultimately depends on your specific requirements and needs.
Related benchmarks:
Sha256
Sha256-2
Sha256-Hex-Effect
sha1-js-rusha-vs-native-10mb
Comments
Confirm delete:
Do you really want to delete benchmark?